js在IE下面弹出打开和保存文件的对话框

 

js在IE下面弹出打开和保存文件的对话框  

2010-08-11 13:39:16|  分类: JavaScript |  标签: |字号 订阅

<html>
<head>
<script>
function   loadDoc()
{
fileDialog.CancelError=true;
        try{
        fileDialog.Filter="HTM   Files   (*.htm)|*.htm|Text   Files   (*.txt)|*.txt";
          fileDialog.ShowOpen();
        var   fso=new   ActiveXObject("Scripting.FileSystemObject");
        var   reading=1;
        var   f=fso.OpenTextFile(fileDialog.filename,reading);
        //window.confirm(f);
        var   r=f.ReadAll();
        f.close();
        TxtBody.value=r;
        }catch(e){}
}
function   saveDoc()
{
fileDialog.CancelError=true;
      try{
      fileDialog.Filter="HTM   Files   (*.htm)|*.htm|Text   Files   (*.txt)|*.txt";
      fileDialog.ShowSave();
      var   fso=new   ActiveXObject("Scripting.FileSystemObject");
      var   f=fso.CreateTextFile(fileDialog.filename,true);
      f.write(TxtBody.value);
      f.Close();
      }
      catch(e){}
}
</script>

</head>
<body>
<object   id="fileDialog"   width="0px"   height="0px"   classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB"   codebase="http://activex.microsoft.com/controls/vb5/comdlg32.cab">
</object>
<textarea   id=TxtBody   style="background-color:#EEEEEE;width:100%;height:100">无标题</textarea>
<br>
<input   type=button   value=加载   οnclick="loadDoc()">
<input   type=button   value=保存   οnclick="saveDoc()">

</html>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值