在javascript中打开本地文件系统中的文件 [英] Opening a file in local file system in javascript
问题描述
我正在寻找一种打开.xls文件的方法,该文件位于临时目录中,在IE和Firefox浏览器中使用javascript。我尝试使用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?
我也尝试过一个empty.html其中有这个javascript并在这个称为openMe()的body上。并从父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
Cheers, 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屋!