JS图片保存到手机相册(ios与android通用)
2020-10-16 17:34
<script type="text/javascript"> function savePic() { var picurl= 'https://www.ecshop51.com/images/202005/goods_img/ecshop51.com-413_P_1589452188884.gif'; //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); } </script>调用代码如下
<a href="javascript:savePic()">保存图片</a>
本文原创地址:https://www.ecshop51.com/article660.html
版权所有 © 转载时必须以链接形式注明出处!
觉得本文对您有用,想收藏下来!方法很简单:请点击-〉
我们一直坚持白天工作、晚上熬夜更新资源,付出了巨大的精力和时间,其中的辛酸难以言述。