[thelist] Proper way to append to a links onclick handler

Roger Ly evolt at matchpenalty.com
Mon Nov 24 19:55:09 CST 2003

Hey all,

I have an HTML page with a link that pops open a URL in a new window.
The link is as follows:

<a href="url.html" onclick="window.open(this.href, 'windowname',
'width=100;height=100'); return false" target="windowname">link</a>

Nothing special really.

However, for users with javascript enabled, we want to intercept clicks
on links on the page, so we have a window.onload function which does
something like this:

function onloadFunction()
	if (document.links)
		for (var i = 0; i < document.links.length; i++)

Again, nothing to special.

Both seem to work when separated, but when I put them together, the
popup window code at the top doesn't work.

So, I figure that in the onload function I have defined to override the
onclick handler of all links on the page, that I need to append any
onload handler that may have already been defined, but unfortunately, I
can't seem to get it to work:

	document.links[i].onclick= clickFunction +

The above doesn't do what I would hope it to do (namely perform the
clickFunction() and then and onclick handler that had been previously
defined by an individual link.

Is there something obvious that I am missing?



More information about the thelist mailing list