Xul: open local html file relative to "myapp.xul" in xul browser

in short: is there a way to find the current path to the full xul application path?

long explanation:

I would like to open some html files in an xul browser application. The path to the html files must be installed programmatically from the xul application. The html files are outside my xul application, but at the same level. (users will check both folders from SVN, without installing the xul application)

It opened the files perfectly if I set the full path, for example, "file: /// c: \ temp \ processing-sample \ index.html"

what i want to do is open the file regarding my xul application.

I found that I can open the path to the user profile:

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); 

is there any way to find the current path to the full xul application path?

+3
3

: 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;
+2

, html -URI. :

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

xul chrome , -url.

, , . , javascript xul :

<script src="chrome://includes/content/XSLTemplate.js" type="application/x-javascript"/>

, , c:\applicationFolder\chrome\content\index.html, :

chrome://content/index.html 

.

You can also look at jslib , a library that simplifies many things, including input / output files. IIRC, I was unable to get to the relative path using "../".

0
source

Source: https://habr.com/ru/post/1697224/


All Articles