get value of link using javascript

I have these two links:

<div class="leave"><a href="">Leave to Google</a></div>
<div class="leave"><a href="">Leave to Yahoo</a></div>

When the user leaves the page this function fires:

function Redirect() {
var where="colorbox_autofire.html";

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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm not sure what the redirection to colorbox_autofire.html is supposed to do, but if I ignore that piece for now, how about something like this:
<div class="leave"><a href="Javascript:;" onClick="Redirect('')">Leave to Google</a></div>
<div class="leave"><a href="Javascript:;" onClick="Redirect('')">Leave to Yahoo</a></div>

<script language="JavaScript">
function Redirect(myLocation) {
//   var where = "colorbox_autofire.html";
//   window.location=where;

// myLocation is a variable that now has the link that was clicked.
   window.location = myLocation;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
You should do a complete work arround to get to your solution. Try this instead:

function redirect(clickedlink)
// currently you have the clicked link in a var named clickedlink
var where="colorbox_autofire.html";

Then you do your links like this:

<div class="leave"><a onclick="javascript:redirect('')" style="cursor:hand">Leave to Google</a></div>
<div class="leave"><a onclick="javascript:redirect('')" style="cursor:hand">Leave to Yahoo</a></div>

I even added some CSS so that the cursor reacts well to the link
elliottbenzleAuthor Commented:
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 ( without applying anything to the link itself. I was thinking of something like:


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 ?

check the previos attribute ;)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.