如何用javascript脚本实现打开像window中的“选择文件”、“另存为”等文件对话框作者:陈格 日期:2007-12-29字体大小: 小 中 大
问:
document.execCommand("open")好象不是直接打开选择文件的对话框。
______________________________________________________________________________________________
答1:
<input type=button value=剪切 οnclick="document.execCommand('Cut')">
<input type=button value=拷贝 οnclick="document.execCommand('Copy')">
<input type=button value=粘贴 οnclick="document.execCommand('Paste')">
<INPUT type=button value=打印 οnclick="document.execCommand('Print')">
<input type=button value=全选 οnclick="document.execCommand('SelectAll')">
<input type=button value=撤消 οnclick="document.execCommand('Undo')">
<input type=button value=删除 οnclick="document.execCommand('Delete')">
<input type=button value=黑体 οnclick="document.execCommand('Bold')">
<input type=button value=斜体 οnclick="document.execCommand('Italic')">
<input type=button value=下划线 οnclick="document.execCommand('Underline')">
<input type=button value=停止 οnclick="document.execCommand('stop')">
<input type=button value=保存 οnclick="document.execCommand('SaveAs')">
<input type=button value=另存为 οnclick="document.execCommand('Saveas',false,'c:\\test.htm')">
<input type=button value=字体 οnclick="document.execCommand('FontName',false,fn)">
<input type=button value=字体大小 οnclick="document.execCommand('FontSize',false,fs)">
<input type=button value=刷新 οnclick="document.execCommand('refresh',false,0)">
______________________________________________________________________________________________
答2:
没打开?
______________________________________________________________________________________________
答3:
先谢过梅花雪:)
______________________________________________________________________________________________
答4:
<input type=file> 这个就可以选择文件了
______________________________________________________________________________________________
答5:
<!-- IE5.5以上 -->
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
<input type=button value=打开 οnclick="document.all.WebBrowser.ExecWB(1,1)">
______________________________________________________________________________________________
答6:
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0></OBJECT>
<input type=button value=打印 οnclick="document.all.WebBrowser.ExecWB(6,1)">
<input type=button value=直接打印 οnclick="document.all.WebBrowser.ExecWB(6,6)">
<input type=button value=页面设置 οnclick="document.all.WebBrowser.ExecWB(8,1)">
<input type=button value=打印预览 οnclick="document.all.WebBrowser.ExecWB(7,1)">
<input type=button value=打开 οnclick="document.all.WebBrowser.ExecWB(1,1)">
<input type=button value=另存为 οnclick="document.all.WebBrowser.ExecWB(4,1)">
<input type=button value=属性 οnclick="document.all.WebBrowser.ExecWB(10,1)">
<input type=button value=全选 οnclick="document.all.WebBrowser.ExecWB(17,1)">
<input type=button value=刷新 οnclick="document.all.WebBrowser.ExecWB(22,1)">
<input type=button value=关闭窗口 οnclick="document.all.WebBrowser.ExecWB(45,1)">
______________________________________________________________________________________________
答7:
老大来了,我就不说话了!
______________________________________________________________________________________________
答8:
我试过用上面的方法,还是会先出现“键入文档或文件夹的Internet地址,......”这个界面,点按键“浏览”后才会出现通用选择对话框。
能不能就直接出现通用选择对话框,而不出现那第一界面,另外能不能设置打开的文件类型?
分不够,另外再开贴,给分:)
______________________________________________________________________________________________
答9:
忘 了说,我是在IE6+windows2000 Pro下
______________________________________________________________________________________________
答10:
<object id=FileDialog style="left: 0px; TOP: 0px" classid="clsid:f9043c85-f6f2-101a-a3c9-08002b2f49fb">
<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>
function OpenFile()
{
FileDialog.CancelError=true;
FileDialog.Filter="Word模板|*.doc|Word模板|*.dot";
FileDialog.ShowOpen();
var WordApp=new ActiveXObject("Word.Application");
WordApp.Application.Visible=false;
var Doc=WordApp.Documents.Open(FileDialog.filename);
Doc.Activate();
Doc.Parent.Options.InsertedTextColor=4;
Doc.Parent.Options.InsertedTextMark=2;
Doc.Parent.Options.DeletedTextColor=4;
Doc.Parent.Options.DeletedTextMark=1;
Doc.TrackRevisions=true;
Doc.PrintRevisions=true;
Doc.ShowRevisions=true;
Doc.Application.UserName="";
var Range=doc.Range();
Range.Select();
var Selection=WordApp.Selection;
Selection.Copy();
App.focus();
document.execCommand("Paste");
App.focus();
WordApp.DisplayAlerts=false;
Doc.Close();
WordApp.DisplayAlerts=true;
WordApp.Quit();
return false;
}
______________________________________________________________________________________________
答11:
To: gjd111686(数字金刚)
你这段代码引用这个控件确实不错, 可是好象在你的JS脚本里有好几个地方有错误吧, 比如: var Range=doc.Range(); 应该是 var Range=Doc.Range(); 还有就是为什么要把整个DOC的内容全部拷贝出来? 那个变量 App 是干什么用的呢? 在哪里被使用呢?
var WordApp=new ActiveXObject("Word.Application"); 这句代码同样会引起客户端的安全警告, 在浏览器的安全设置比较高点的时候会报错.
______________________________________________________________________________________________
答12:
有没有解决方法?