我有onbeforeunload事件的自定义消息,并且运行良好但我今天注意到它不再显示我的消息了.相反,它显示"您所做的更改可能无法保存"
window.onbeforeunload = function () {
return 'Custom message'
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以让我知道如何解决它?
如果用户注意离开包含未保存设置的页面,我希望显示警告,但显然不是在他们尝试保存这些设置时.
我想我的理解是错误的,因为我认为下面应该有效,但事实并非如此.有人能告诉我我做错了什么吗?谢谢.
$('input[name="Submit"]').off('onbeforeunload');
window.onbeforeunload = function closeEditorWarning(){
/** Check to see if the settings warning is displayed */
if($('#unsaved-settings').css('display') !== 'none'){
bol_option_changed = true;
}
/** Display a warning if the user is trying to leave the page with unsaved settings */
if(bol_option_changed === true){
return '';
}
};
Run Code Online (Sandbox Code Playgroud)