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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Triggering event when user leaves website

Status
Not open for further replies.

cgillin

Programmer
Mar 20, 2003
58
US
I want to be able to trigger an event(open a new window) when a user leaves my website whether it be via closing the browser or going to another url that isn't part of my site. onUnload won't work because I don't want this event to occur everytime users leave a specific page.

If anyone has any ideas or have figured out this problem before please let me know.

Thanks for the help,
Chris
 
Use an "onunload" attribute :

Code:
<html>
<head>

<script language="Javascript">
function leavePage() {
  alert ('leaving');
}
</script>
</head>

<body onUnload="leavePage()">

</body>
</html>
 
Guess I'm not really sure what that will do for me. I only want the event to occur when they leave my entire site, not specific pages. Another problem onunload creates is when submitting a form that is on pages which will cause an event to occur upon submission.
 
there is that - maybe use it a bit more intelligently (somehow ?!)
 
Indeed. Apologies, after re-reading your post I noticed you had already disposed on "unonload" as one of your options.

To be fair though, this is the only real method available to determine if a user is leaving a page - all be it to another site, or exiting the browser. Afer all, you cannot determine a user's thoughts eh ?! I'm if you give it some thought, you may be able to come up with an algorithm to obtain the correct behaviour...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top