Solved

How to detect when the user closes the browser

Posted on 2001-06-14
7
235 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Expert Comment

by:a.marsh
ID: 6193140
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
ID: 6193849
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
ID: 6194398
Perfect!! And I was beginning to think it just wasn't possible! Many thanks, Rob.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:pagemastah
ID: 6194808
does this run both in IE and Netscape?

this is effective!
0
 

Author Comment

by:robbiemorgan
ID: 6194892
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
ID: 6195065
nilapenn: How does this trick work? Just curious...
0
 
LVL 2

Expert Comment

by:sjhyam
ID: 6198052
Me Too...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

756 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