js文件下载

第一种下载方式:
      <a href="www.baid.aaa.zip">下载</a>


第二种下载方式:
<a href="www.baid.aaa.zip" id="pic1" onclick="savepic();return false;">点击下载</a>

<script>  
    function savepic(){  
        if(document.all.a1==null){  
              objIframe=document.createElement("IFRAME");  
              document.body.insertBefore(objIframe);  
              objIframe.outerHTML=   "<iframe name='a1' style='width:0;hieght:0' src="+pic1.href+"></iframe>";  
              re=setTimeout("savepic()",1)  
        }else{  
             clearTimeout(re)  
             pic   =   window.open(pic1.href,"a1")  
             pic.document.execCommand("SaveAs")  
             document.all.a1.removeNode(true)  
         }
   }  
</script>

注:浏览器能直接打开的不能下载,支持浏览器不能直接打开的可下载。

猜你喜欢

转载自pxy.iteye.com/blog/2327812
今日推荐