I have a main page that has a couple of requires.
In one of those requires, I want to trigger a javascript onload. Is there any code to trigger a javascript on load, without adding it at the opening <body> tag?
Thanks
HoraShadow
Printable View
I have a main page that has a couple of requires.
In one of those requires, I want to trigger a javascript onload. Is there any code to trigger a javascript on load, without adding it at the opening <body> tag?
Thanks
HoraShadow
Event handler registration should always be done exclusively through the Javascript code files (you do have them in separate files right? Good) using addEventListener() and its sad cousin required for IE compatibility, attachEvent().
So, for a load event handler:
You could also grab my event registration wrapper which reduces the process to one line:Code:if (window.addEventListener)
window.addEventListener('load', doOnload, false);
else if (window.attachEvent)
window.attachEvent('onload', doOnload, false);
function doOnload(e)
{
// ...
}
Make sure you include that file first before any other JS includes.Code:addEHandler(window, 'load', doOnload);
Thanks man. I will try it.
And yes, the JS are in separated files. :)
HoraShadow