gpt4 book ai didi

javascript - xul: 在 xul 浏览器中打开一个相对于 "myapp.xul"的本地 html 文件

转载 作者:行者123 更新时间:2023-11-29 10:26:03 28 4
gpt4 key购买 nike

简而言之:有什么方法可以找到 xul 应用程序的当前目录完整路径吗?

详细解释:

我想在 xul 浏览器应用程序中打开一些 html 文件。应该从 xul 应用程序以编程方式设置 html 文件的路径。 html 文件位于我的 xul 应用程序的文件夹之外,但处于同一级别。 (用户将从 SVN 中 check out 这两个文件夹,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 应用程序的当前目录完整路径?

最佳答案

我找到了解决方法:http://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO我无法使用相对路径“../../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;

关于javascript - xul: 在 xul 浏览器中打开一个相对于 "myapp.xul"的本地 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/104267/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com