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!

function to call when closing a browser?

Status
Not open for further replies.

daveigh

Programmer
Oct 9, 2003
105
is there a specific function in javascript i can call or create when a user closes a browser? not when it redirects to another page? i used onUnload but it also triggers when i redirect to another page..any feedback?

_______________CRYOcoustic_____________
 
No, as far as the event model is concerned there is no difference between moving to a different location or closing the browser. Hence onunload is fired whenever the current page is "unloaded", regardless of how.

What is it that you are trying to achieve, maybe there is a better way?

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.
 
ic..I wish to track down the users who doesnt continue on checkout process. there are some instances on my site that there's a lot of page views & site visitors, but nobody buys anything! i might think of another way...

_______________CRYOcoustic_____________
 
Try something like this:

Code:
<html>
<head>
<script>
var doIt = true;
function alertUnload()
{
 if(doIt)
 {
  alert("You're closing the window!");
 }
 else
 {
  doIt = true;[b]//must reset to true for proper functioning[/b]
 }
}
</script>
</head>
<body onunload='alertUnload()'>
<a href='[URL unfurl="true"]http://www.google.com'[/URL] onclick='[b]doIt=false;[/b]'>Redirect to Google</a>
</body>
</html>

If all your links change the doIt var to false with their ONCLICK event, then the body of the function called with the ONUNLOAD event will never fire.

'hope that helps.

--Dave
 
To be honest with you, if I decide to hold off on purchasing something at a site after partially completing things, I am quite annoyed by popups pushing me to buy something at that time. Sites like that generally lose my business permanently.

Be careful about annoying potential customers.

Lee
 
dont worry, trollacious..m quite a customer myself..the popup i made will close after 2 secs..

thanks for the code snippet, dave.

_______________CRYOcoustic_____________
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top