用javascript打开本地文件系统中的文件 [英] Opening a file in local file system in javascript

查看:35
本文介绍了用javascript打开本地文件系统中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在 IE 和 Firefox 浏览器中使用 javascript 打开临时目录中的 .xls 文件的方法.我尝试使用 javascript 如下,

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","");
}

names.xls 文件存在于那里,我已经验证过了.由于安全问题,IE 7.0 不允许用户打开空白窗口,因此我无法完成这项工作.我还没有用firefox检查过它.有什么办法可以让它工作吗?

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?

我也试过有一个空的.html,它有这个javascript并在onLoad上调用这个openMe()主体.并从父 HTML 文件中打开 empty.html.我看到的只是一个新的空白窗口,什么也没有,但文件没有打开.

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

干杯,阿比

推荐答案

抱歉,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!

这篇关于用javascript打开本地文件系统中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆