checks if the X button was clicked on browser window
The following code returns true if user clicks on Close button else false. This code you can use it on events window.unload or window.onbeforeunload
- function isUserClickedCloseButton()
-
{
-
-
var browserWindowWidth = 0;
-
var browserWindowHeight = 0;
-
// gets the width and height of the browser window
-
if (parseInt(navigator.appVersion) > 3)
-
{
-
if (navigator.appName == "Netscape")
-
{
-
browserWindowWidth = window.innerWidth;
-
browserWindowHeight = window.innerHeight;
-
}
-
if (navigator.appName.indexOf("Microsoft") !=- 1)
-
{
-
browserWindowWidth = top.window.document.body.offsetWidth;
-
browserWindowHeight = top.window.document.body.offsetHeight;
-
}
-
}
-
// checks if the X button was closed
-
// if event.clientY < 0, then click was on the browser menu area
-
// if event.screenX > (browserWindowWidth - 25), the X button was clicked
-
// use screenX if working with multiple frames
-
return (event.clientY < 0 && event.screenX > (browserWindowWidth - 25)) ? true : false;
-
}