[Javascript] Capturing which link/button is clicked

Peter-Paul Koch gassinaumasis at hotmail.com
Tue Nov 27 02:43:33 CST 2001



>For reasons I don't pretend to ignore, a colleague has set up a form so
>that no matter which link is clicked on, an onUnload script changes the
>location. For example:
>
><a href="goToThisPage.html">Go here</a>
>
>onUnload="window.location.href='goToThisPageInstead.html'"
>
>(The URL in onUnload isn't actually an HTML page, but a Domino agent that
>runs onUnload. Just using .html above for clarity.)
>
>Anyway, I now need to find a way to capture the URL on the link that was 
>actually clicked. Compounding this problem is that not all clickable things 
>are links; some are buttons that run other agents, or javascript functions.

You have to set onclick events on all this stuff and then read out the 
hrefs. For instance, for all links

var a = document.getElementsByTagName('A');
for (var i=0;i<a.length;i++)
   a[i].onclick = detect;

Now all links have a onClick event handler that sends the onclick to

function detect(e)
{
  if (e) tg = e.target;
  else tg = window.event.srcElement;
  theHref = tg.[I've forgotten, link?, href?]
}

I've forgotten how to get the href out of tg, which is now a link like in 
document.links[]

Now you have the href of the link clicked on. However, how are you going to 
send it outside the page if the page unloads directly after this detect and 
goes somewhere else?

I'm not sure what you're supposed to make happen.

ppk

_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




More information about the Javascript mailing list