window.open之后 document.execCommand('SaveAs','xxx.htm');

解决方案 »

  1.   

    <input type="text" id="txt"/>
    <input type="button" onclick="SaveAs()" value="Save"/>
    <iframe name="IF" id="IF" style='display:none'></iframe>
    <script type="text/javascript">
    function SaveAs()
    {
      var v=document.getElementById('txt').value;
      var doc=document.frames("IF").document;
      doc.write(v);
      doc.execCommand('SaveAs','a.htm');
      doc.body.innerHTML="";//清除原来的内容
      //doc.location.reload();
    }
    </script>
      

  2.   

    <input type="text" id="txt"/>
    <input type="button" onclick="SaveAs()" value="Save"/>
    <iframe name="IF" id="IF" style="display:none"></iframe>
    <script type="text/javascript">
    function SaveAs()
    {
      var v=document.getElementById('txt').value;
      var doc=document.frames("IF").document;
      doc.write(v);
      doc.execCommand('SaveAs','a.htm');
      //doc.body.innerHTML="";//清除原来的内容
      doc.location.reload();//还是用这个来清除,上面的清除不了,晕
    }
    </script>
      

  3.   

    var fd = new ActiveXObject("MSComDlg.CommonDialog");
    fd.Filter = "Text File(*.txt)|*.txt";
    fd.FilterIndex = 2;
    fd.MaxFileSize = 128;
    fd.ShowSave();
    fso=new ActiveXObject("Scripting.FileSystemObject"); 
    f1=fso.CreateTextFile(fd.filename,true); 
    f1.WriteLine(txtID.innerText); //txtID为文本框id 
    f1.Close();浏览器可能需要一定的权限才能进行以上操作