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

Tomas Kokoska koksa.uh at seznam.cz
Tue Nov 25 05:40:19 CST 2003


You must use more complicated syntax to get what you want.

document.links[i].onclick = function() {document.links[i].onclick;
clickFunction;};

operator "+" doesn't work this way.

Tom

----- Original Message -----
From: "Roger Ly" <evolt at matchpenalty.com>
To: <thelist at lists.evolt.org>
Sent: Tuesday, November 25, 2003 2:55 AM
Subject: [thelist] Proper way to append to a links onclick handler


> 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++)
> {
> document.links[i].onclick=clickFunction;
> }
> }
> }
>
> 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 +
> document.links[i].onclick;
>
> 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?
>
> Thanks,
>
> Roger
>
> --
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>



More information about the thelist mailing list