:
if (window === null || typeof window !== "object") {
//If you do not already have a window reference, you need to obtain one:
// Add/remove a "/" to comment/un-comment the code appropriate for your add-on type.
/* Add-on SDK:
var window = require('sdk/window/utils').getMostRecentBrowserWindow();
//*/
//* Overlay and bootstrap (from almost any context/scope):
var window=Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator)
.getMostRecentWindow("navigator:browser");
//*/
}
if (typeof document === "undefined") {
//If there is no document defined, get it
var document = window.content.document;
}
これはほぼすべてのコンテキストで機能します。
ボタンからcommand
イベントへの応答としてこのコードが実行されていることをコメントに記載しました。
var window = event.view;
var document = window.content.document;
document
は、イベントが発生したウィンドウ内の現在のタブのHTML文書になること:それはあなたが使用することができさえハンドラであることを考えます。
let gBrowser = window.gBrowser;
let primeDocument = window.document;//The primary document container for that Firefox window.
let mainXULWindow = window.document.getElementById("main-window");
を私が興味を持っている:私はちょうど 'content.document'をしようとすると、私はcontent'ではない'ことを見つける上記のいずれかのために
、あなたが役立つかもしれないいくつかの追加のオブジェクトを取得することができます定義された。 'content'を定義するコードは何ですか? – Makyen@Makyen XULツールバーのボタンを押す - 私はvar doc = content.documentを呼び出す関数を呼び出します。興味深い。 –
再起動しないXULベースのアドオンでテストしています。関数は、Firefoxのツールバーボタンのコマンドイベントのハンドラから呼び出されます。私の場合、 'typeof content' =' 'undefined ''です。コードのどこかに 'content'を定義していないのですか? – Makyen