Home > front end >  H5 page use js to save the current photo albums to mobile phones
H5 page use js to save the current photo albums to mobile phones

Time:10-17

New people for the first time to do save images to the function of mobile phone photo album, to give advice or comments

CodePudding user response:

 
Var triggerEvent="touchstart";//specified download

The function saveAs (Url) {
Var blob=new blob ([...] and {type: 'application/octet stream -'});
Var url=url. CreateObjectURL (blob);
Var a=document. The createElement method (' a ');
A.h ref=https://bbs.csdn.net/topics/Url;
A. d. ownload Url=replace (/(. * \/) * ([^.] +. *)/ig, "$2"). The split ("?" ) [0];
Var e=document. CreateEvent (' MouseEvents');
E.i nitMouseEvent (' click ', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
A. d. ispatchEvent (e);
URL. RevokeObjectURL (URL);
}

Var imgs=document. GetElementsByTagName (" img ");
For (var I=0, o; O=imgs [I]; I++) {
O.a ddEventListener (triggerEvent, function () {
Var url=this. GetAttribute (" SRC ");
SaveAs (url);
},false);
}

CodePudding user response:

For help, click the download button, no download images, proposed separately

CodePudding user response:

You have to solve?

CodePudding user response:

reference 4 floor lucy5555 response:
have to solve?

reference XIZHOUXIANG reply: 3/f
for help, click the download button, no download images, proposed separately

 
Let a=document. The createElement method (" a ");//generates an a element
Let the event=new MouseEvent (" click ");//create a click event
A. d. ownload='image name' | | "photo".//set the picture name
A.s tyle. Display='none';
A.h ref='https://bbs.csdn.net/topics/image path;
A. d. ispatchEvent (event);//triggers the click event of a

This way is ok, you try

  • Related