簡而言之:有什麼方法可以找到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