JS 实现图片直接下载

来源:互联网 发布:平面设计有什么软件 编辑:程序博客网 时间:2024/05/16 23:49
<a href="picName.jpg"   id=pic1 onclick="savepic();return false;"style="cursor:hand">点击下载</a>    
  1. <script type="text/javascript"
  2. function savepic() {  
  3.             if (document.all.a1 == null) {  
  4.                 objIframe = document.createElement("IFRAME");  
  5.                 document.body.insertBefore(objIframe);  
  6.                 objIframe.outerHTML = "<iframe name=a1 style='width:400px;hieght:300px' src=" + imageName.href + "></iframe>";  
  7.                 re = setTimeout("savepic()", 1)  
  8.             }  
  9.             else {  
  10.                 clearTimeout(re)  
  11.                 pic = window.open(imageName.href, "a1")  
  12.                 pic.document.execCommand("SaveAs")  
  13.                 document.all.a1.removeNode(true)  
  14.             }  
  15.         }   
  16. </script>  


0 0
原创粉丝点击