We help IT Professionals succeed at work.

Lotus/Javascript Guru's here is your chance

pcorreya
pcorreya asked
on
I need to capture the href value when a user click on any links on the page. Can I do it as a global
event capture, everytime someone clicks a link.
Comment
Watch Question

Why don't you have a function which is called from a href link to give you the name of the link which is clicked

Like this

<SCript Language="javascript">
function msg(input) {
alert(input);
}
</Script>

<a href="http://www.yahoo.com" onClick="msg(this)">yahoo</a>

<a href="http://www.lycos.com" onClick="msg(this)">lycos</a>

~Hemanth

Author

Commented:

Author

Commented:
Hemanth,

This is an existing site so I can't change links etc. I need to somehow globally capture this info.

Regards
Patrick
Commented:
Hello Patrick,

this works fine for me:
function clickhref(obj)
{
  alert(obj.href);
}

function doc_onload()
{
 for(i=0;i<document.links.length;i++)
   document.links[i].onclick=function(){clickhref(this)}
}


Can you please point out when you get links wich already have onClick defined so I can test a circumvention.

So long,
zvonko

PS: please note the missing new directive in function assignment :-)
Wow...!  you like this kinda pts is it ?

<|;-)

Author

Commented:
works fine. Thanks

Commented:
...especially the feedback :-)

Thank you for the points Patrick <|:-)

Huh ??? :-(

;-)

Explore More ContentExplore courses, solutions, and other research materials related to this topic.