Click to See Complete Forum and Search --> : read url of clicked link


icarusca
11-16-2003, 07:53 PM
I'd like to be able to read the url of a link a user has clicked on.

I want to do some post-click processing on certain pages, so I thought I could have an onUnload event read urls as they are clicked on.

<head>

function check_url() {
my url = ??
}

</head>
<body onUnload=check_url()>

location.href and it's ilk don't work as they refer to the current page, not the link that was clicked on.

Any idea how to get this info? or am I going about it the wrong way?

thanks,

icarusca

Jona
11-16-2003, 08:33 PM
<script type="text/javascript">
/* Untested Code */
document.onload = function(){
&nbsp; for(i=0; i<document.links.length; i++){
&nbsp; &nbsp; document.links[i].onclick=function(){
&nbsp; &nbsp; &nbsp; check_url(this.href);
&nbsp; &nbsp;}
&nbsp;}
}

function check_url(loc){
&nbsp; alert("You clicked a link that will take you to "+loc);
}
</script>


[J]ona

fredmv
11-16-2003, 09:29 PM
<script type="text/javascript">
onload = function()
{
a = document.getElementsByTagName('a');
for(i=0; i<a.length; i++) a[i].onclick = function() { alert('URL: ' + this.href); }
}
</script>