qbox Posted July 13, 2008 Share Posted July 13, 2008 Hi to all I read on internet one script and look like this window.addEventListener("load", function() { myExtension.init(); }, false); var myExtension = { init: function() { var appcontent = document.getElementById("appcontent"); // browser if(appcontent) appcontent.addEventListener("DOMContentLoaded", myExtension.onPageLoad, true); var messagepane = document.getElementById("messagepane"); // mail if(messagepane) messagepane.addEventListener("load", function () { myExtension.onPageLoad(); }, true); }, onPageLoad: function(aEvent) { var doc = aEvent.originalTarget; // doc is document that triggered "onload" event // do something with the loaded page. // doc.location is a Location object (see below for a link). // You can use it to make your code executed on certain pages only. if(doc.location.href.search("forum") > -1) alert("a forum page is loaded"); } from http://developer.mozilla.org/en/docs/Code_snippets:On_page_load I can't understand this code. What is the function? What this do? Why is in this way? What is that init line and what he do? Thank you. Quote Link to comment Share on other sites More sharing options...
corbin Posted July 14, 2008 Share Posted July 14, 2008 From what I understand, you attach that to the UI of Firefox, and it will execute everytime a page loads. For example, the addEventListener call is simply saying "make it so when ever the window loads the functino myExtension.init() is run." Then, myExtension is simply a variable with a class in it, and init is a method. Then onPageLoad simply sets something to be done when the page loads (In this case, if the URL contains "forum" in it, an alert box will popup and say "a forum page is loaded"). Quote Link to comment Share on other sites More sharing options...
qbox Posted July 14, 2008 Author Share Posted July 14, 2008 What line is executed first? Can you tell me a little more about init method? Quote Link to comment Share on other sites More sharing options...
qbox Posted July 14, 2008 Author Share Posted July 14, 2008 Like I understand with init: function{ ...... OnLoad(); } OnLoad(){ ... } with init function I can call OnLoad function to execute without to indicate in body tag, and I can set some var values who are already set before without indicating again. Im right or not? Quote Link to comment Share on other sites More sharing options...
corbin Posted July 15, 2008 Share Posted July 15, 2008 Ahh my post earlier was wrong. I misread the brackets. It seems that init is called when the page is loaded, and init makes a call to onPageLoad. So, err, I'm not sure what you're asking x.x. Quote Link to comment Share on other sites More sharing options...
qbox Posted July 16, 2008 Author Share Posted July 16, 2008 Thanks I understand the code. But another problem on the way.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.