Solved

How to detect when the user closes the browser

Posted on 2001-06-14
7
231 Views
Last Modified: 2008-02-01
Hi,

Does anyone know of a way to detect when the user closes their browser (And only when they close their browser).

The only way I've discovered to do it, is to tie some code to the 'onUnload' event of the HTML body, but of course that gets triggered whenever the page gets unloaded, i.e. on refresh, back, etc, and not just when the user closes the browser.

Any ideas?

Is there some way I could use ASP to my advantage?

Many thanks,

Rob
0
Comment
Question by:robbiemorgan
7 Comments
 
LVL 15

Expert Comment

by:a.marsh
Comment Utility
This is likely to be the best code you are going to get:

http://developer.irt.org/script/1578.htm

Ant
0
 
LVL 5

Accepted Solution

by:
nilapenn earned 100 total points
Comment Utility
Try This


<SCRIPT LANGUAGE="JavaScript">
<!--
function RorC() {

var top=self.screenTop;
if (top>9000)
{alert('window was closed')}
else
{alert('window was Refreshed')}
}

//-->
</SCRIPT>

</HEAD>
<BODY BGCOLOR="#FFFFFF" onunload="javascript:if (document.all){RorC()} else {var top=window.outerWidth;if
(top==0) {opener.alert('window was closed')} else {opener.alert('window was Refreshed')}}">
gfds
</BODY>
0
 

Author Comment

by:robbiemorgan
Comment Utility
Perfect!! And I was beginning to think it just wasn't possible! Many thanks, Rob.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Expert Comment

by:pagemastah
Comment Utility
does this run both in IE and Netscape?

this is effective!
0
 

Author Comment

by:robbiemorgan
Comment Utility
Fortunately that's not a concern for me in this particular instance. But if you do get a chance to try it, please let me know!
0
 
LVL 3

Expert Comment

by:dnoelpp
Comment Utility
nilapenn: How does this trick work? Just curious...
0
 
LVL 2

Expert Comment

by:sjhyam
Comment Utility
Me Too...
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now