Link to home
Start Free TrialLog in
Avatar of gweidner
gweidner

asked on

Capturing the window close event

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?
Avatar of jeebukarthikeyan
jeebukarthikeyan
Flag of India image

hi,

try this

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


b u d d h a
Avatar of gweidner
gweidner

ASKER

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.
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks guys, the links were a great help.