在javascript中打开本地文件系统中的文件
我正在寻找一种在 IE 和 Firefox 浏览器中使用 javascript 打开临时目录中的 .xls 文件的方法。我尝试使用 javascript,如下所示,
function openMe(){
var newwindow=window.open("file:///{path to temp dir}/names.xls","window2","");
}
names.xls 文件存在,我已经验证了它。由于安全问题,IE 7.0 不允许用户打开空白窗口,因此我无法完成此操作。我还没有用firefox检查过。有什么方法可以让它发挥作用吗?
我还尝试使用一个包含此 javascript 的empty.html 并在onLoad 上调用此openMe() 主体。并从父 HTML 文件中打开empty.html。我所看到的只是一个新的空白窗口,什么都没有,但文件无法打开。
任何指点都会非常有帮助。
谢谢干杯, 阿比
I am looking out for a way to open a .xls file which is in temp directory using javascript in IE and Firefox browser. I tried using the javascript as follows,
function openMe(){
var newwindow=window.open("file:///{path to temp dir}/names.xls","window2","");
}
The names.xls file exists there, I have verified it. As IE 7.0 does not let a user open a blank window due to security issues I am unable to make this work. I have not checked it with firefox yet. Is there any way to get this working?
I also tried having an empty.html which has this javascript and calling this openMe() body onLoad. And opening the empty.html from the parent HTML file. All I see is a new blank window without nothing but the file does not open.
Any pointers would be greatly helpful.Thanks
Cheers,
Abi
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
抱歉,Abi,你运气不好——你无法在浏览器中使用 JavaScript 打开本地文件系统上的文件。这是一个安全问题,如果您仔细考虑一下,就完全有道理了;您不希望人们在其网站上编写可以访问本地文件系统上的文件并可能从中读取数据的脚本!
Sorry, Abi, you're out of luck--you can't use JavaScript in a browser to open a file on the local file system. This is a security issue and makes perfect sense if you think about it; you wouldn't want people writing scripts on their web sites that can access files on your local file system and possibly read data from them!
只要计算机用户选择文件,HTML5 就允许打开本地文件。您应该能够在此处找到有关 JavaScript API 的更多信息以及有关如何使用该 API 的示例代码:http://www.html5rocks.com/en/tutorials/file/dndfiles/
HTML5 permits opening of local files as long as the computer user is selecting the files. You should be able to find more information on the JavaScript API along with sample code on how to use that API here: http://www.html5rocks.com/en/tutorials/file/dndfiles/
建议您使用AJAX。小型 API 如下。
Suggest you use AJAX. Small API follows.