|
-
Aug 20th, 2006, 11:44 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] trigger javascript onload from an include file?
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
I do like the reward system. If you find that my post was useful, rate it.
-
Aug 21st, 2006, 01:55 AM
#2
Re: trigger javascript onload from an include file?
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:
Code:
if (window.addEventListener)
window.addEventListener('load', doOnload, false);
else if (window.attachEvent)
window.attachEvent('onload', doOnload, false);
function doOnload(e)
{
// ...
}
You could also grab my event registration wrapper which reduces the process to one line:
Code:
addEHandler(window, 'load', doOnload);
Make sure you include that file first before any other JS includes.
-
Aug 22nd, 2006, 12:43 AM
#3
Thread Starter
Fanatic Member
Re: trigger javascript onload from an include file?
Thanks man. I will try it.
And yes, the JS are in separated files. 
HoraShadow
I do like the reward system. If you find that my post was useful, rate it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|