3

要するに、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 アプリケーションの現在のディレクトリのフルパスを見つける方法はありますか?

4

3 に答える 3

2

はい、拡張機能内の html ファイルは、chrome URI を使用してアドレス指定できます。私の拡張機能の例:

content.document.location.href = "chrome://{appname}/content/logManager/index.html"
于 2009-02-25T03:57:21.317 に答える
2

回避策を見つけました: http://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO相対パス "../../index.html" を使用してファイルを正確に開くことはできませんが、 app ディレクトリを開き、それを操作します。

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;
于 2008-09-19T19:48:13.173 に答える
0

xul アプリケーションでは、chrome url を使用してアプリケーションの chrome フォルダーにアクセスできます。

私は要素の経験が比較的少ないため、これが正確に機能するかどうかはわかりません. これは、xul ファイルに JavaScript ソース ファイルを含める方法です。

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

したがって、おそらくファイルが c:\applicationFolder\chrome\content\index.html にある場合は、次の場所からアクセスできます。

chrome://content/index.html 

ある方法で。

また、ファイル I/O を含む多くのことを簡素化するライブラリであるjslibも参照してください。IIRC、「../」を使用して相対パスに到達するのに苦労しました。

于 2008-09-20T05:14:29.520 に答える