Solved

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

Posted on 2004-10-04
6
168 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
6 Comments
 
LVL 36

Accepted Solution

by:
Zyloch earned 25 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 25 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
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…

773 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