Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

onUnload: which link is clicked ?

Status
Not open for further replies.

haroonqurehi

Programmer
Jul 22, 2004
5
US
Is it possible in onUnload event to catch which link is clicked that invokes new page(new URL request to browser, either through address bar or any link through web site or form post )

like if I am and second.html link is clicked, is it possible to catch this second.html link in onUnload event of first.html ?

Thanks
 
I was thinking something like the below but I'm not sure it'll work in most browsers. (Only tested in Mozilla.) What is it you want to do anyway?

Code:
<script>

window.onclick = function( e ) {

	if ( !e ) var e = window.event;
	if ( e.target ) targ = e.target;
	else if ( e.srcElement ) targ = e.srcElement;
	if ( targ.nodeType == 3 ) // defeat Safari bug
		targ = targ.parentNode;
}

window.onunload = function() {

	if ( targ.tagName == "A" )
		alert( "Link clicked to: " + targ.href );
}

</script>

<a href="[URL unfurl="true"]http://www.google.com">google.com</a>[/URL]
 
This is great, thnx a lot

This resolves half of the problem.

If I close the browser without doing anything and write alert(targ) in onUnload event, this doesn't work.

Actually I am trying to catch the event(target URL), if user goes to any other page OR if user closes the browser.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top