how to handle window close event in all aspects?
i.e. when window is closed using close button
alt+f4
and closing the window by right clicking on the task bar
how to handle window close event in all aspects?
i.e. when window is closed using close button
alt+f4
and closing the window by right clicking on the task bar
window.unload detects all of those along with all the other ways to close the browser and unloading the page in order to reload it and unloading the page in order to load a different page. There is no way to distinguish from JavaScript as to why the page is being unloaded.
but somehow i have to find out that the window is closed…by any means
is there any alternative way
You can trigger a javascript function on the ‘onunload’ event but it will cause that function to be performed each time the page is refreshed, closed or when u navigate to other place.
Here is a code that detects browser close in IE.
But it won’t work if you navigate to a different page.(using a link or address bar, or refresh using mouse.)
window.onunload = function()
{
if ((window.event.clientX < 0) || (window.event.clientY<0)) // close button
{
alert("Window Closed");
}
else if (window.event.altKey == true) // ALT + F4
{
alert("Window Closed");
}
else // for all other unload events
{
alert("unload event");
}
}
Hope this helps.
thanks Mr. unnikris, its working
but how to make this work on mozilla firefox?