elliottbenzle
asked on
get value of link using javascript
I have these two links:
<div class="leave"><a href="http://www.google.com">Leave to Google</a></div>
<div class="leave"><a href="http://www.yahoo.com">Leave to Yahoo</a></div>
When the user leaves the page this function fires:
<script>
function Redirect() {
var where="colorbox_autofire.h tml";
window.location=where;
}
</script>
through the body onUnLoad:
<body onUnLoad="Redirect()">
Before the user is redirected I want to get the href value of the link they clicked and store it in a variable. How would I do this?
Thanks
<div class="leave"><a href="http://www.google.com">Leave to Google</a></div>
<div class="leave"><a href="http://www.yahoo.com">Leave to Yahoo</a></div>
When the user leaves the page this function fires:
<script>
function Redirect() {
var where="colorbox_autofire.h
window.location=where;
}
</script>
through the body onUnLoad:
<body onUnLoad="Redirect()">
Before the user is redirected I want to get the href value of the link they clicked and store it in a variable. How would I do this?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This was what I thought of too. But I'm not in control of the links. I need to be able to get that value (http://www.google.com) without applying anything to the link itself. I was thinking of something like:
document.a.href.clickedval ue
does this make any sense?
document.a.href.clickedval
does this make any sense?
Holy cow, this is the third time today someone post the solution just before me :(
Maybe better to check the History object in Javascript ?
http://www.comptechdoc.org/independent/web/cgi/javamanual/javahistory.html
check the previos attribute ;)
http://www.comptechdoc.org/independent/web/cgi/javamanual/javahistory.html
check the previos attribute ;)
<script>
function redirect(clickedlink)
{
// currently you have the clicked link in a var named clickedlink
var where="colorbox_autofire.h
window.location=where;
}
</script>
Then you do your links like this:
<div class="leave"><a onclick="javascript:redire
<div class="leave"><a onclick="javascript:redire
I even added some CSS so that the cursor reacts well to the link