?
Solved

Capturing the window close event

Posted on 2007-10-16
8
Medium Priority
?
1,313 Views
Last Modified: 2013-12-08
Is there a way to capture the window close event using javascript? Using the 'onbeforeunload' or 'onblur' does not help in my case as the user might navigate to another page in the same application and these events will be fired.   Is there an event which is fired only when the browser window gets closed?
0
Comment
Question by:gweidner
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 20083899
hi,

try this

<body onUnload=alert('am going'); self.blur();>


b u d d h a
0
 
LVL 13

Expert Comment

by:jeebukarthikeyan
ID: 20083917
0
 
LVL 1

Author Comment

by:gweidner
ID: 20084182
Thanks Buddha, but onUnload is called whenever the page gets unloaded, be it navigating to another page in the same application or even when the page is refreshed.   I am looking for an event which is triggered when the window is closed using the 'X' button.
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.

 
LVL 4

Expert Comment

by:NickWalt
ID: 20084322
Add a global.asax file using the Add/New wizard. There is a neat block in there for Application Start and End. Probably would be the Session Start and End events though, as the application could be running for multiple users. The Session is an individual running the program.
0
 
LVL 1

Author Comment

by:gweidner
ID: 20084352
Hi Nick, I have the global.asax file and i actually want to fire the Session_End event handler even when the user closes the browser window because Session_End does not get fired when the browser window is closed.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 150 total points
ID: 20084802
0
 
LVL 4

Expert Comment

by:NickWalt
ID: 20084818
0
 
LVL 1

Author Comment

by:gweidner
ID: 20091016
Thanks guys, the links were a great help.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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)
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 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