Javascript xul:打开一个相对于“的本地html文件”;myapp.xul“;在xul浏览器中

Javascript xul:打开一个相对于“的本地html文件”;myapp.xul“;在xul浏览器中,javascript,file-io,xul,Javascript,File Io,Xul,简而言之:有没有办法找到xul应用程序的当前目录完整路径? 详细解释: 我想在xul浏览器应用程序中打开一些html文件。html文件的路径应该从xul应用程序以编程方式设置。html文件位于xul应用程序的文件夹之外,但处于同一级别。(用户将从SVN签出这两个文件夹,xul应用程序没有可用的安装) 如果我设置一个完整的路径,比如“file:///c:\temp\processing sample\index.html“ 我要做的是打开与xul应用程序相关的文件 我发现我可以打开用户的配置文件路

简而言之:有没有办法找到xul应用程序的当前目录完整路径?

详细解释:

我想在xul浏览器应用程序中打开一些html文件。html文件的路径应该从xul应用程序以编程方式设置。html文件位于xul应用程序的文件夹之外,但处于同一级别。(用户将从SVN签出这两个文件夹,xul应用程序没有可用的安装)

如果我设置一个完整的路径,比如“file:///c:\temp\processing sample\index.html“

我要做的是打开与xul应用程序相关的文件

我发现我可以打开用户的配置文件路径:

var DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1", "nsIProperties");
var path = (new DIR_SERVICE()).get("UChrm", Components.interfaces.nsIFile).path;
var appletPath;

// find directory separator type
if (path.search(/\\/) != -1)
{
appletPath = path + "\\myApp\\content\\applet.html"
}
else
{
appletPath = path + "/myApp/content/applet.html"
}

// Cargar el applet en el iframe
var appletFile = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
appletFile.initWithPath(appletPath);
var appletURL = Components.classes["@mozilla.org/network/protocol;1?name=file"].createInstance(Components.interfaces.nsIFileProtocolHandler).getURLSpecFromFile(appletFile);
var appletFrame = document.getElementById("appletFrame");
appletFrame.setAttribute("src", appletURL); 
有没有办法找到xul应用程序的当前目录完整路径?

我找到了一个解决方法:我无法使用相对路径“./../index.html”准确打开文件,但我可以获取应用程序目录并使用它

var DIR_SERVICE = new Components.Constructor("@mozilla.org/file/directory_service;1", "nsIProperties");
var path = (new DIR_SERVICE()).get(resource:app, Components.interfaces.nsIFile).path;
var appletPath;

在xul应用程序中,可以使用ChromeURL访问应用程序的chrome文件夹

我对该元素的经验相对较少,所以我不确定这是否适合您。这是在xul文件中包含javascript源文件的方式:

<script src="chrome://includes/content/XSLTemplate.js" type="application/x-javascript"/>
以某种方式


您还可以查看一个库,它简化了很多事情,包括文件i/o。IIRC,我在使用“../”访问相对路径时遇到问题。

是的,扩展名中的html文件可以使用chrome URI寻址。 我的一个扩展中的一个示例:

content.document.location.href = "chrome://{appname}/content/logManager/index.html"

实际上,您可以使用文件路径设置browser
src
属性,但需要使用“chrome://”sintax,如@bizzy。
content.document.location.href = "chrome://{appname}/content/logManager/index.html"