• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

How to detect when the user closes the browser

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
robbiemorgan
Asked:
robbiemorgan
1 Solution
 
a.marshCommented:
This is likely to be the best code you are going to get:

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

Ant
0
 
nilapennCommented:
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
 
robbiemorganAuthor Commented:
Perfect!! And I was beginning to think it just wasn't possible! Many thanks, Rob.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
pagemastahCommented:
does this run both in IE and Netscape?

this is effective!
0
 
robbiemorganAuthor Commented:
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
 
dnoelppCommented:
nilapenn: How does this trick work? Just curious...
0
 
sjhyamCommented:
Me Too...
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now