• js 图片保存至手机相册


    1.网络地址进行保存

    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);
        }
    savePicture(Url); 
    // Url 为图片的服务器地址  http://****.com/cwap/images/userqrcode/06144477550415791.pngfinal.png

    2.临时地址也可以保存: blob:http://localhost:8080/d08f95f2-06da-4f9c-864e-c00079fc1c6f
    var file = files[0];//上传控件选择的文件对象
    var url = window.URL.createObjectURL(file);//用此方法有兼容问题
    savePicture(Url); 
    
    
    //下面是兼容方法
    
    //获取图片路径
    function getObjectURL (file){
      let url = null ;
      if (window.createObjectURL!=undefined) { // basic
        url = window.createObjectURL(file) ;
      } else if (window.URL!=undefined) { // mozilla(firefox)
        url = window.URL.createObjectURL(file) ;
      } else if (window.webkitURL!=undefined) { // webkit or chrome
        url = window.webkitURL.createObjectURL(file) ;
      }
      return url ;
    }

    转: https://blog.csdn.net/weixin_43271750/article/details/97639465

  • 相关阅读:
    利用URL protocol在网页打开本地exe
    [Leetcode]50. Pow(x, n)
    【转载】初识google test
    MySQL主从配置【转载】
    MySQL源码安装(centos)
    MySQL数据库MyISAM和InnoDB存储引擎的比较【转载】
    MySQL 事务
    MySQL 对于千万级的大表要怎么优化
    MySQL性能优化的最佳21条经验【转载】
    mysql日志详细解析【转载】
  • 原文地址:https://www.cnblogs.com/fps2tao/p/12941066.html
Copyright © 2020-2023  润新知