检测何时加载firefox扩展名的页面

时间:2022-11-01 19:36:15

How to detect when a page is loaded (in any tab) with a firefox extension (automatically, no start-button or anything) (and display an alert message for example) ?

如何检测页面加载(在任何选项卡中)具有firefox扩展名(自动,没有开始按钮或任何东西)(并显示警报消息)?

2 个解决方案

#1


https://developer.mozilla.org/en/Code_snippets/On_page_load

Dont miss this part: "

不要错过这个部分:“

Current Firefox trunk nightlies will fire the onPageLoad function for not only documents, but xul:images (favicons in tabbrowser). If you only want to handle documents, ensure aEvent.originalTarget.nodeName == "#document" 1.

当前的Firefox主干晚会将触发onPageLoad函数,不仅是文档,还有xul:images(tabbrowser中的favicons)。如果您只想处理文档,请确保aEvent.originalTarget.nodeName ==“#document”1。

"

#2


function startup() {

mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIWebNavigation)
                         .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                         .rootTreeItem
                         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIDOMWindow); 

    mainWindow.getBrowser().addEventListener("load", listener, false);


    // Sidebar is loaded and mainwindow is ready                   
    }

    var listener = function(e){
        alert("Hai");
        //To remove event listener
        //mainWindow.getBrowser().removeEventListener("load",listener, false);
    }  


window.addEventListener("load", startup, false);

This is code is enough for this purpose.

这个代码就足够了。

Though this is late, I'm answering this question to minimize the search time.

虽然这已经很晚了,但我正在回答这个问题,以尽量减少搜索时间。

#1


https://developer.mozilla.org/en/Code_snippets/On_page_load

Dont miss this part: "

不要错过这个部分:“

Current Firefox trunk nightlies will fire the onPageLoad function for not only documents, but xul:images (favicons in tabbrowser). If you only want to handle documents, ensure aEvent.originalTarget.nodeName == "#document" 1.

当前的Firefox主干晚会将触发onPageLoad函数,不仅是文档,还有xul:images(tabbrowser中的favicons)。如果您只想处理文档,请确保aEvent.originalTarget.nodeName ==“#document”1。

"

#2


function startup() {

mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIWebNavigation)
                         .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                         .rootTreeItem
                         .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                         .getInterface(Components.interfaces.nsIDOMWindow); 

    mainWindow.getBrowser().addEventListener("load", listener, false);


    // Sidebar is loaded and mainwindow is ready                   
    }

    var listener = function(e){
        alert("Hai");
        //To remove event listener
        //mainWindow.getBrowser().removeEventListener("load",listener, false);
    }  


window.addEventListener("load", startup, false);

This is code is enough for this purpose.

这个代码就足够了。

Though this is late, I'm answering this question to minimize the search time.

虽然这已经很晚了,但我正在回答这个问题,以尽量减少搜索时间。