通过js保存图片到本地 – 花海果都 – 博客频道 – CSDN.NET

JS代码:

[html] view plaincopyprint?

  1. <span><span> >  
  2. <html>  
  3.  <head>  
  4.   <title> 通过js保存图片到本地 title>  
  5.   <meta name=“Generator” content=“EditPlus”>  
  6.   <meta name=“Author” content=“”>  
  7.   <meta name=“Keywords” content=“”>  
  8.   <meta name=“Description” content=“”>  
  9.   <script src=“http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js” type=“text/javascript”>script>  
  10. head>  
  11.   
  12.   
  13.  <body>  
  14.   <input type=“button” value=“download image” onclick=“DownLoadReportIMG(‘http://www.oursss.com/uploads/photo/1045_2590.jpg?rd=0.9961522558898981’);”>    
  15.  body>  
  16. html>span>span>  

JS代码:

[javascript] view plaincopyprint?

  1. function DownLoadReportIMG(imgPathURL) {  
  2.            
  3.         //如果隐藏IFRAME不存在,则添加  
  4.         if (!document.getElementById(“IframeReportImg”))  
  5.             $().appendTo(“body”);  
  6.         if (document.all.IframeReportImg.src != imgPathURL) {  
  7.             //加载图片  
  8.             document.all.IframeReportImg.src = imgPathURL;  
  9.         }  
  10.         else {  
  11.             //图片直接另存为  
  12.             DoSaveAsIMG();    
  13.         }  
  14.     }  
  15.     function DoSaveAsIMG() {  
  16.         if (document.all.IframeReportImg.src != “about:blank”)  
  17.             document.frames(“IframeReportImg”).document.execCommand(“SaveAs”);          
  18.     }  

来源URL:http://blog.csdn.net/zajin/article/details/17113501