h5页面使用js实现保存当前图片到手机相册

 

 

很可惜,这个鬼东西微信内置浏览器不适用

 

页面:

复制代码



    
    
    节日贺卡
    
    
    
    
    
    
    




节日贺卡

保存到相册
复制代码

js:

复制代码
/**
 * Created by wwj on 2019/03/11.
 */
$(document).ready(function(){
    pageShow = 9;
    nowPage = 1;
    loadDataId="my_poster_id";
    /*var url = window.basePath + "/h5/front/poster/toPoster";
    $.ajax({
        url: url,
        type: 'GET',
        dataType: 'json',
        data: {},
        success: function (rest) {
            $("#salesmanUuid").val(rest.data.salesmanUuid);
        }
    })*/

    pageCallBack()
});
function pageCallBack(){
    loadPosterContent();
}
function loadPosterContent(){
    var storeNo = getSessionStoreNo();
    var posterType = $("#posterType").val();
    var url = window.basePath + "/h5/front/poster/ajaxSearchPoster";
    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'json',
        data: {currentPage: nowPage,pageShow:pageShow,storeNo:storeNo,posterType:posterType},
        success: function (rest) {
            console.log(rest)
            if(rest.result){
                appendPosterResult(rest);
            }else{
                $(".no_search_data").show();
            }
            console.log('start')
        }
    })
}
//拼接加载出来的产品
function appendPosterResult(data){
    var results = data.results;
    if(results!=null&&results.length>0){
        var appendHtml = "";
        for(var i=0;i

'+poster.posterTitle+'

'; appendHtml +='
  • ' +'

    '+poster.posterTitle+'

    ' +'
  • '; } $("#my_poster_id").append(appendHtml); $(".no_search_data").hide(); }else{ if(nowPage==1){ totalPage = data.totalPage; $(".no_search_data").show(); } } nowPage++; initPreviewJs(); } //初始化图片预览效果js function initPreviewJs(){ $(".haibao-list li img").click(function(){ var imgSrc = $(this)[0].src; $(".mark").fadeIn(); $(".haibao-show").fadeIn().children("img").attr("src",imgSrc); }) $(".btn-close-haibao,.mark").click(function(){ $(".mark").fadeOut(); $(".haibao-show").fadeOut(); $("#successHint").hide(); $("#failHint").hide(); }) } //保存到相册 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); }
    复制代码

     

     

    参考博客:https://blog.csdn.net/rentian1/article/details/84988590

    你可能感兴趣的:(h5页面使用js实现保存当前图片到手机相册)