1. Avoid pop-up prompt box
I searched a lot on the Internet, and the answers are mostly set to window.onbeforeunload=null, but they are invalid after trial.
After leaving this question for two days, I returned to think about it again. Finally found the answer. I will share it with you here:
Unbind the pop-up content after jquery leaves the page (1) First unbind and set the pop-up content to null.
The code copy is as follows:
$(function(){
$(window).unbind('beforeunload');
window.onbeforeunload = null;
})
2. Other related [Abstract]
(1) Onunload and onbeforeunload events of window
The following refers to the implementation in js, rather than the <body onunload="close()"> method!
Because this is triggered when unloading the body, and no matter any browser, unloading the body will be unloading the body when it is closed!
Model 1:
The code copy is as follows:
function close(){
alert("this is a test");
}
window.onbeforeunload=close;
Model 2:
The code copy 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 the code
About Model 1:
1). Refresh, multiple windows and single windows are suitable.
2). Single window ie closes the entire ie trigger.
3).ie7 close single page trigger in multiple windows
4) Other multi-window refresh triggers. Turning off single and closing the entire one does not trigger
For Model 2:
1).Eie single window and ie7 multiple windows must be closed before triggering
2). Refresh other multi-window browsers. Close a single page and close the entire page without triggering
(2) Create a leave prompt box
Bind beforeunload event
The code copy is as follows:
$(window).bind('beforeunload',function(){
return 'The content you entered has not been saved yet. Are you sure you leave this page? ';
});
Unbind
The code copy is as follows:
$(window).unbind('beforeunload');
window.onbeforeunload = null;
The above is all the content described in this article, I hope you like it.