I listen for a onload event on a main window, then for a DOMContentLoaded event on each browser/tab (I need run the code inside a browser at the most) and flag with controlExecuted that the code was run on a browser.
window.addEventListener("load", function(){
try{
var controlExecuted = 0;
var appcontent = document.getElementById("appcontent"); // browser
if (appcontent && controlExecuted == 0)
appcontent.addEventListener("DOMContentLoaded", function docLoader(e){
appcontent.removeEventListener("DOMContentLoaded", docLoader, false);
alert('run code')
controlExecuted = 1;
}, true);
}catch(e){
// log!
}
}, false);
This not works. The code run several times depending of the number of browsers/tabs.
So how to run only one instance of code in a firefox addon?
Here the complete solution to run only one instance of code in a firefox addon using JavaScript code modules.
The main calling code:
Sure that you can improve it. Comment using @nomikos if you do.
THX.