加载本地网页到Firefox的JavaScript

加载本地网页到Firefox的JavaScript

问题描述:

用于加载本地文件到Firefox我注意到...加载本地网页到Firefox的JavaScript

location.href = "./relative/path/file.htm"; //this works 
location.href = "http://localhost/path/file.htm"; //this works 
location.href = "file:///c:/absolute/path/file.htm"; //doesnt work (also doesnt work if remove the "file:///" bit) 

我想获得最后一个示例工作。是否有一些about.config设置可以添加来允许这个或者“netscape.security.PrivilegeManager ...”语句?

(这是一个特殊的Firefox配置文件,不适合一般用途,所以不安全问题是不相关的)。 谢谢。

+0

有什么不对使用file:///语法? – BeRecursive 2012-01-05 18:00:06

+0

@BeRecursive。我的意思是,如果我这样做:“file:// c:/absolute/path/file.htm”它也不起作用。 – spiderplant0 2012-01-05 18:01:15

+0

是在http上调用此代码的页面? – epascarello 2012-01-05 18:43:38

使用“文件:///”当你需要使用你需要键入 文件,因为它从文件浏览器访问的物理地址,换句话说反斜杠(窗口)(窗口)

不要忘记与“\\”的逃生。

例如:

var url = "file:///c:\\myDir\\1.html";