IE中弹出打开/保存文件对话框

打开/保存文件对话框:

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function   loadDoc()
{
fileDialog.CancelError=true;
        try{
        fileDialog.Filter="HTM   Files   (*.htm)|*.htm|Text  Files   (*.txt)|*.txt|XML   Files   (*.xml)|*.xml|ALL   Files   (*.*)|*.*";
        fileDialog.ShowOpen();
        var   fso=new   ActiveXObject("Scripting.FileSystemObject");
        var   reading=1;
        var   f=fso.OpenTextFile(fileDialog.filename,reading);
        //window.confirm(f);
        var   rValue=f.ReadAll();
        f.close();
        TxtBody.value=rValue;
        }catch(e){}
}
function   saveDoc()
{
fileDialog.CancelError=true;
      try{
      fileDialog.Filter="HTM   Files   (*.htm)|*.htm|Text  Files   (*.txt)|*.txt|XML   Files   (*.xml)|*.xml|ALL   Files   (*.*)|*.*";
      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:300px;">文本内容</textarea>
<br>
<input   type="button"   value="加载"   οnclick="loadDoc()" />
<input   type="button"   value="保存"   οnclick="saveDoc()" />
</html>

 

WEB中类似OpenFileDialog功能


<HTML>  
  <HEAD>  
  </HEAD>  
  <body   MS_POSITIONING="GridLayout">  
  <form   id="WebForm1"   method="post"   runat="server">  
  <OBJECT   style="Z-INDEX:   106;   LEFT:   38px;   POSITION:   absolute;   TOP:   168px" 

 classid="clsid:F9043C85-F6F2-101A-A3C9-08002B2F49FB"   name="CommandDialog1">  
  <PARAM   NAME="_ExtentX"   VALUE="847">  
  <PARAM   NAME="_ExtentY"   VALUE="847">  
  <PARAM   NAME="_Version"   VALUE="393216">  
  <PARAM   NAME="CancelError"   VALUE="0">  
  <PARAM   NAME="Color"   VALUE="0">  
  <PARAM   NAME="Copies"   VALUE="1">  
  <PARAM   NAME="DefaultExt"   VALUE="">  
  <PARAM   NAME="DialogTitle"   VALUE="">  
  <PARAM   NAME="FileName"   VALUE="">  
  <PARAM   NAME="Filter"   VALUE="">  
  <PARAM   NAME="FilterIndex"   VALUE="0">  
  <PARAM   NAME="Flags"   VALUE="0">  
  <PARAM   NAME="FontBold"   VALUE="0">  
  <PARAM   NAME="FontItalic"   VALUE="0">  
  <PARAM   NAME="FontName"   VALUE="">  
  <PARAM   NAME="FontSize"   VALUE="8">  
  <PARAM   NAME="FontStrikeThru"   VALUE="0">  
  <PARAM   NAME="FontUnderLine"   VALUE="0">  
  <PARAM   NAME="FromPage"   VALUE="0">  
  <PARAM   NAME="HelpCommand"   VALUE="0">  
  <PARAM   NAME="HelpContext"   VALUE="0">  
  <PARAM   NAME="HelpFile"   VALUE="">  
  <PARAM   NAME="HelpKey"   VALUE="">  
  <PARAM   NAME="InitDir"   VALUE="">  
  <PARAM   NAME="Max"   VALUE="0">  
  <PARAM   NAME="Min"   VALUE="0">  
  <PARAM   NAME="MaxFileSize"   VALUE="260">  
  <PARAM   NAME="PrinterDefault"   VALUE="1">  
  <PARAM   NAME="ToPage"   VALUE="0">  
  <PARAM   NAME="Orientation"   VALUE="1">  
  </OBJECT>  
  <INPUT   type="button"   value="保存"   name="btn1">  
  <INPUT   type="button"   value="打开"   name="btn2">  
  </form>  
  <script   language="vbscript">  
  option   explicit  
   
  sub   btn1_onclick()  
  WebForm1.CommandDialog1.Filter="Text   File(*.txt)|*.txt"  
  WebForm1.CommandDialog1.showSave()  
  end   sub  
   
  sub   btn2_onclick()  
  WebForm1.CommandDialog1.Filter="Text   File(*.txt)|*.txt"  
  WebForm1.CommandDialog1.showOpen()  
  end   sub  
  </script>  
  </body>  
  </HTML>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值