[thelist] Appending actions to event handlers in Javascript

Roger Ly evolt at matchpenalty.com
Tue Oct 21 18:43:55 CDT 2003


Hey all,

I'm having a problem trying to assign an onload handler to a couple of
pages.  Both pages have a Javascript include, which contains the
following:

window.onload = doSomething;

function doSomething()
{
	//blah
}


On one page, I just have a plain <body> tag, and when the page is
loaded, it correctly fires off the doSomething() function.

On the other page, I have a <body> tag with its on onload handler:
<body onload="doThis();">

I am assuming that the window.onload assignment I am doing in the
Javascript include is failing because either a) the body already has an
onload handler defined, and I can't change it or b) the window.onload
assignment is happening first, and the <body> tag is overriding that
assignment with its own function.

In either case, is there a way for my javascript include to append a
function to a <body>'s existing onload handler?

I have some new functionality that I want to add to some existing pages,
but I would like to avoid having to add a new function to each <body>
tag, and would like to just include the .js file which assigns the
correct function (allowing me to easily add/remove functionality in the
future without having to update every html page in my site).

Any help would be appreciated,

Thanks,

Roger



More information about the thelist mailing list