Renn
 

  HTML代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> 通过js保存图片到本地 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
</head>

<body>
<input type="button" value="download image" onclick="DownLoadReportIMG(\'http://www.oursss.com/uploads/photo/1045_2590.jpg?rd=0.9961522558898981\');">
</body>
</html>

  

  JS代码:

function DownLoadReportIMG(imgPathURL) {
        
        //如果隐藏IFRAME不存在,则添加
        if (!document.getElementById("IframeReportImg"))
            $(\'<iframe style="display:none;" id="IframeReportImg" name="IframeReportImg" onload="DoSaveAsIMG();" width="0" height="0" src="about:blank"></iframe>\').appendTo("body");
        if (document.all.IframeReportImg.src != imgPathURL) {
            //加载图片
            document.all.IframeReportImg.src = imgPathURL;
        }
        else {
            //图片直接另存为
            DoSaveAsIMG();  
        }
    }
    function DoSaveAsIMG() {
        if (document.all.IframeReportImg.src != "about:blank")
            document.frames("IframeReportImg").document.execCommand("SaveAs");        
    }

  

分类:

技术点:

相关文章:

  • 2021-06-12
  • 2021-10-09
  • 2021-12-26
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
  • 2022-01-02
猜你喜欢
  • 2022-03-03
  • 2022-02-08
  • 2021-09-08
  • 2022-12-23
  • 2022-02-10
  • 2021-12-22
相关资源
相似解决方案