将picurl的值赋值为图片地址,可以是网络图片地址或本地临时路径图片,时间调用savePic()函数
function savePic(){ var picurl= $("#picurl").attr("src"); //alert(picurl); savePicture(picurl); }
var triggerEvent = "touchstart"; function savePicture(Url){ var blob=new Blob([''], {type:'application/octet-stream'}); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = Url; a.download = Url.replace(/(.*\/)*([^.]+.*)/ig,"$2").split("?")[0]; var e = document.createEvent('MouseEvents'); e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); a.dispatchEvent(e); URL.revokeObjectURL(url); }
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!