1. the browser is not a software window. It is very difficult to identify the event because closing and refreshing events are difficult to distinguish.
2. There are no corresponding events, which can only be determined based on certain conditions, but may not be accurate.
3. forward, backward, refresh, and close all respond to event window. onbeforeunload.
4. The reason why javascript can obtain certain event attributes and call methods is that the browser object provides interfaces for it. In terms of COM, it is an idispatch interface, if the browser object does not provide interfaces for him, he cannot do anything. Therefore, some functions can be implemented in other languages, but cannot be implemented in JavaScript.
OnUnload Method
Add an onUnload Event to the body tag
Body onUnload = "myclose ()"
Then define the myclose () method in Javascript, but the onUnload method is executed after the window is closed, not before the window is closed. If you want to make a judgment before closing the window, please use the first method
function getevent () /// compatible with both IE and FF writing, this method is online copy
{< br> If (document. all) return window. event;
func = getevent. caller;
while (fun C! = null ) {
var arg0 = func. arguments [0];
If (arg0)
{< br> If (arg0.constructor = event | arg0.constructor = mouseevent)
| (Typeof(Arg0) = "object" & arg0.preventdefault & arg0.stoppropagation ))
{
ReturnArg0;
}
}
Func = func. Caller;
}
Return Null;
}
Function Confirmclose (){
If (Window. Event ){
Window. event. returnvalue = "Make sure you have saved the information before closing the window! ";
} Else {
Getevent (). preventdefault (); // For Firefox
}
}
Function On_page_loaded (){ // Onload event of the custom body
Try {
If (! Window. onbeforeunload ){ // In order not to overwrite the original onbeforeunload method, first judge
Window. onbeforeunload = confirmclose; // The prompt before the window is closed is added to todo.
}
} Catch (E ){}
}
<Body onload = "on_page_loaded ()">
// Determine whether the parent form is closed before opening the form
FunctionRsseek (){
If(Opener ){
If(Typeof(Registry.opener.doc ument) = 'unknown '|Typeof(Registry.opener.doc ument) = 'undefined '){
//Disabled
}Else{
Opener. myseekok ();
}
}
}