Solved

How to detect when the user closes the browser

Posted on 2001-06-14
7
232 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using javascript confirmation for a delete in mysql 5 29
HTML5 Get data in table rows 5 26
HTML5 frame 5 25
jQuery - following an example but can I save data server side? 20 46
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
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…

813 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

11 Experts available now in Live!

Get 1:1 Help Now