Possible Duplicate:
window.onbeforeunload not working in chrome
Am facing a problem with handling the browser's window / tab close event in javascript. I tried and googled many cases to trigger my function before closing the browser's window / tab.
In my function i should display a simple alert message as below:
function doBeforeClose(){
// do work needed
alert("you have successfully logged out");
}
I tried to trigger this function by
<body onbeforeunload="doBeforeClose()">
or
window.onbeforeunload = function(evt){ .... }
I am able do call this function in IE and Mozilla, but not in Chrome. I got to know that there is a bug in chrome for capturing this event (may be a bug or a feature for security issues).
Even this doesn't fulfill my requirement as this event should trigger only on close event, not page unload.
i.e, its getting called on refresh / redirection of the pages.
To avoid this on refresh i captured events for F5 and Ctrl_R, but not able to capture refresh button event.
I tried to capture refresh button event by getting mouse coordinates, but it is not at all recommended option as all browser's alignment of buttons wont be same.
Please do needful.