Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to have two window.onload events?

Status
Not open for further replies.

tcstom

Programmer
Joined
Aug 22, 2003
Messages
235
Location
GB
I've noticed that if you include two external Javascript files and both add functions to the window.onload event then only one will work. Is there a way to enable both to work? I want to have a reusable external script file that can be dropped into web pages that may already use window.onload. Maybe is there an alternative to onload?
 
you can create a function that calls the two functions...

Code:
function doOnload() {
    doFunc1();
    doFunc2();
}

function doFunc1() {
    alert('hi');
}

function doFunc2() {
    alert('hello');
}

onload=doOnload;

there are a couple other ways as well...



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks, but I'm talking about just dropping a script that contains an onload handler into a page that already references a script that contains its own onload handler. I don't want to have to modify either script, so was really wondering if there was a way for the contents of one onload handler to be appended to the contents of the other rather than overwriting the other. e.g.
Code:
window.onload += function() {...

Or something like that. (Although I expect what I want isn't possible!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top