【转】js实现另存为的方法

示例代码:

<input   type=button   value=另存为   onclick="mm1()">  

<iframe   width=0   height=0   frameborder=0   name=hrong   style="display:   none"></iframe>
      <script language="JavaScript">
      //有窗口弹出的下载
     /* function openfile()
       {    
           var a;
           a =window.open("下载文件的URL","_blank", "width=0, height=0");
           a.document.execCommand("SaveAs");    
           a.close();  
      } */
      //无窗口弹出

      function   mm1()  
    {  
          var str="下载文件的URL";    
          window.frames["hrong"].location.href   =   str;  
          sa();  
}  
function   sa()  
{  
        if(window.frames["hrong"].document.readyState!="complete")  
            setTimeout("sa()",   100);  
      else  
          window.frames["hrong"].document.execCommand('SaveAs');  
}  
      </script>

原文地址:https://www.cnblogs.com/ifishing/p/1748663.html