views:

930

answers:

2

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.

Anyone able to point me in the right direction?

+2  A: 

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"){
     }
     }
}
A: 

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

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