从Firefox侧边栏监控选定选项卡中的页面加载事件

时间:2022-04-16 19:47:14

I want to be able to run a function in my firefox sidebar js file when the selected tab in the main content window is reloaded or changed. So the sidebar can change depending on the site the user is looking at.

我希望能够在重新加载或更改主内容窗口中的选定选项卡时在我的firefox侧边栏js文件中运行一个函数。因此,侧边栏可以根据用户正在查看的站点进行更改。

Anyone able to point me in the right direction?

有人能指出我正确的方向吗?

2 个解决方案

#1


2  

My solution pilfered from somewhere but can't remember where:

我的解决方案从某个地方偷走但不记得在哪里:

//add the load eventListener to the window object
window.addEventListener("load", function() { functioname.init(); }, true);


var functionname =  { 
    //add the listener for the document load event
init: function() {
    var appcontent = document.getElementById("appcontent");   // browser
    if(appcontent)
        appcontent.addEventListener("DOMContentLoaded", functionname.onPageLoad, false);
    },
    //function called on document load
    onPageLoad: function(aEvent) {
        if(aEvent.originalTarget.nodeName == "#document"){
        }
     }
}

#2


0  

@oly1234 - your answer helped me to find the source:
Mozilla Developer Center - On page load

@ oly1234 - 您的回答帮助我找到了源代码:Mozilla开发人员中心 - 页面加载

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

#1


2  

My solution pilfered from somewhere but can't remember where:

我的解决方案从某个地方偷走但不记得在哪里:

//add the load eventListener to the window object
window.addEventListener("load", function() { functioname.init(); }, true);


var functionname =  { 
    //add the listener for the document load event
init: function() {
    var appcontent = document.getElementById("appcontent");   // browser
    if(appcontent)
        appcontent.addEventListener("DOMContentLoaded", functionname.onPageLoad, false);
    },
    //function called on document load
    onPageLoad: function(aEvent) {
        if(aEvent.originalTarget.nodeName == "#document"){
        }
     }
}

#2


0  

@oly1234 - your answer helped me to find the source:
Mozilla Developer Center - On page load

@ oly1234 - 您的回答帮助我找到了源代码:Mozilla开发人员中心 - 页面加载

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