全站插件24小时自动发货

JS图片保存到手机相册(ios与android通用)

<script type="text/javascript">
function savePic()
{
    var picurl= 'https://www.ecshop.cx/images/202005/goods_img/ECSHOP.CX-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.edait.cn/article-660.html
版权所有 © 转载时必须以链接形式注明出处!

觉得本文对您有用,想收藏下来!方法很简单:请点击-〉

文章评论

暂无评论,来发表一个吧

发表 取消
ECSHOP插件网微信客服edait_cn