How to Disable Are you sure you want to navigate away from this page? messagebox in onbeforeunload

强颜欢笑 提交于 2020-01-06 03:51:06

问题


I use the following onbeforeunload for call when the browser close.I get the alert properly also i get the Are you sure you want to navigate away from this page? message box automatically generate by the web browser.But I no need to display that message box when the browser is close.How to disable Are you sure you want to navigate away from this page? messagebox?

window.onbeforeunload = function(event) 
{

           if($.browser.msie)
           {
               alert('Test');
               return false;
            }

 } 

回答1:


Don't return a value, ie:

return;

Or, since the condition is a constant factor:

if($.browser.msie) {
    window.onload = function() {alert('Test');};
} else {
    window.onbeforeunload = function(event) {
        return 'Are you sure to quit?'; // <-- Message is displayed in *some* browsers
    }
}

If you're trying to implement a method which prevents the user from navigating away: There is no way to achieve that. It'd be a horrible experience to not be able to leave a page.



来源:https://stackoverflow.com/questions/11152780/how-to-disable-are-you-sure-you-want-to-navigate-away-from-this-page-messagebox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!