萬盛學電腦網

 萬盛學電腦網 >> 腳本專題 >> javascript >> JS實現點擊下載的小例子

JS實現點擊下載的小例子

這篇文章介紹了JS實現點擊下載的小例子,有需要的朋友可以參考一下   復制代碼 代碼如下:


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <a   href="a.txt"   id=pic1   onclick="savepic();return false;"   style="cursor:hand">點擊下載</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>

copyright © 萬盛學電腦網 all rights reserved