?
Solved

How to handle the close(X) event of a browser

Posted on 2004-10-04
6
Medium Priority
?
190 Views
Last Modified: 2010-04-06
Hi,
I am developing a web application using asp.net. I want to handle the close(X) event of the browser and want to do some database updation before closing the browser. How can i do this?

regards
sudhir
0
Comment
Question by:sudhir_arao
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 100 total points
ID: 12224315
Hi sudhir_arao,

Use Javascript onunload in the <body> tag. Have it call __doPostBack (not sure since not too good with ASP, but heard of it)

Regards,
Zyloch
0
 
LVL 6

Assisted Solution

by:snavebelac
snavebelac earned 100 total points
ID: 12224689
It is very difficulty to trap the closing of a browser as there is no specific event associated with it.  The onUnload event will trigger when a user closes the browser, refreshes, clicks the back button or goes to another page.  There is no way of knowing which has been carried out.

The only way to know when a user has stopped using your web page is via the 'Session_OnEnd' either via a logout of some sort or a timeout on the server.

I am not familiar with ASP.NET but with ASP the global.asp file holds the Session_OnEnd event which will trigger code at the server when a user logouts (associated with the session.adandon function in ASP) or when the session times out (default 20 mins).

HTH

C
0
 
LVL 36

Expert Comment

by:Zyloch
ID: 12225255
Ah yes, use onclose for Mozilla, for IE, here's an implementation: http://experts-exchange.com/Web/Web_Languages/JavaScript/Q_20926025.html

Regards...
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

831 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