简而言之:有什么方法可以找到xul应用程序的当前目录完整路径吗?xul:在xul浏览器中打开一个与“myapp.xul”相关的本地html文件
长解释:
我想在XUL浏览器应用程序中打开某些HTML文件。应该从xul应用程序以编程方式设置html文件的路径。这些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应用程序的当前目录的完整路径?
其实,你可以设置浏览器`src`与文件的路径属性,但你需要使用的“Chrome://” sintax,像@bizzy回答。 – 2010-11-19 13:32:35