简体   繁体   English

使用我的自定义弹出窗口覆盖onbeforeunload弹出窗口

[英]Override onbeforeunload popup with my custom popup

Is there any way that i can override onbeforeunload popup ? 有什么办法可以覆盖onbeforeunload弹出窗口吗?

I tried with below but it does't work: 我在下面尝试但是它不起作用:

if($('body').hasClass('admin')){
    window.onbeforeunload = function(event) {
        notifySaveChangesUser(event);   
        //return null;
        //event.returnValue = "Say";
    };
}

function notifySaveChangesUser(event){
    //Doing some stuff here
}

This question has been already answered here . 这个问题已在这里得到解答。

TL;DR: You can customize message by returning the desired string from the handler: TL; DR:您可以通过从处理程序返回所需的字符串来自定义消息:

window.onbeforeunload = function() {
    return "You have some unsaved changes";
};

See the answer above for more details and browser quirks. 请参阅上面的答案以获取更多详细信息和浏览器怪癖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM