http://www.blogjava.net/wyz191/archive/2008/12/08/245089.html JSwindow.onunload=function () {
var n=window.event.screenx-window.screenleft;
var b=n>document.documentelement.scrollwidth-20;
if (b&&window.event.clienty<0| | Window.event.altKey) {
Alert ("Off");
}else{
Alert ("Refresh");
}
}
Both Firefox and IE support the onbeforeunload event in the three major browsers, which opera has yet to support.
Usage:
- Object.onbeforeunload = Handler
- <element onbeforeunload = "Handler" ... ></element>
Describe:
When the event is triggered, a dialog box with OK and cancel is popped up, and then the page is left, and the cancellation continues on this page.
Handler can set a return value as the display text for the dialog box.
Triggered at:
- Close the browser window
- When you go to another page through the address bar or the Favorites folder
- Click Back, go ahead, refresh, home page one of the time
- Click on a URL to a different page to connect to the time
- When invoking any of the following events: Click,document write,document open,document close,window Close, window navigate, window Navigateandfind, Location Replace,location Reload,form Submit.
- When you open a page with window open and pass the name of the window on this page to the page you want to open.
- When the value of Location.href is re-assigned.
- When submitting a form with the specified action via the input type= "submit" button.
Can be used in the following elements:
BODY, FRAMESET, window
Platform Support:
Ie4+/win, Mozilla 1.7a+, Netscape 7.2+, firefox0.9+
The label has only the Onload\onunload\onbeforeunload event, not the OnClose event. The OnUnload event occurs regardless of whether the page is closed or refreshed. How do I snap to a page close? When the page loads only when the onload page is executed, only the OnUnload page is executed when the onbeforeunload is executed, and then OnUnload, the last onload. This way we can add a tag to the onbeforeunload and judge the tag in the onunload to see if the page is actually closed.
JS to determine if the browser is closed