How does one enable chrome to pop up "are you sure you want to leave this area?" When closing the page ?", Chrome close page
I. Avoid a prompt box
I searched a lot on the Internet. Most of the answers are window. onbeforeunload = null, but it is invalid after trial.
After two days, I returned and thought again, and finally found the answer. I would like to share with you the following:
Remove jquery from the pop-up page. (1) unbind it first. Set the pop-up content to null.
Copy codeThe Code is as follows:
$ (Function (){
$ (Window). unbind ('beforeunload ');
Window. onbeforeunload = null;
})
Ii. Other related [Abstract]
(1)Window onunload and onbeforeunload events
This method is implemented in js instead of <body onunload = "close ()">!
This is triggered when the body is unloaded, and no matter what browser, it will unload the body when it is closed!
Model 1:
Copy codeThe Code is as follows:
Function close (){
Alert ("this is a test ");
}
Window. onbeforeunload = close;
Model 2:
Copy codeThe Code is as follows:
Function close (){
If (document. body. clientWidth-event.clientX <170 & event. clientY <0 | event. altKey)
{
Alert ("this is a test ");
}
}
Window. onbeforeunload = close;
Copy code
About Model 1:
1). Refresh. Multiple windows and single windows are suitable.
2). Close the entire ie trigger in a Single Window.
3). ie7 multiple window close single page trigger
4) Other Multi-Window refresh triggers. Closing a single window or closing a window is not triggered.
For Model 2:
1). For ie single window and multiple ie7 windows, the entire browser must be closed to trigger
2). Refresh other multi-window browsers. Close the single page and close the whole page.
(2)Create exit prompt box
Bind a beforeunload event
Copy codeThe Code is as follows:
$ (Window). bind ('beforeunload', function (){
Return 'the content you entered has not been saved. Are you sure you want to exit this page? ';
});
Unbind
Copy codeThe Code is as follows:
$ (Window). unbind ('beforeunload ');
Window. onbeforeunload = null;
The above is all the content described in this article. I hope you will like it.