Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何更改浏览器';s在卸载之前发送消息_Javascript_Jquery - Fatal编程技术网

Javascript 如何更改浏览器';s在卸载之前发送消息

Javascript 如何更改浏览器';s在卸载之前发送消息,javascript,jquery,Javascript,Jquery,我想在卸载窗口之前更改浏览器消息,下面是我试图处理的代码 var displayMessage = true; $(window).bind('beforeunload', function(){ if(displayMessage){ var message = '-- You specify a custom message here ---'+'\n Thanks for visiting my site!'; return message;

我想在卸载窗口之前更改浏览器消息,下面是我试图处理的代码

var displayMessage = true;
$(window).bind('beforeunload', function(){
    if(displayMessage){
        var message =  '-- You specify a custom message here ---'+'\n Thanks for visiting my site!';
        return message;
    }
});
通过上面的代码,我在firefox上得到的信息是

此页面要求您确认是否要离开-您输入的数据可能无法保存


如何将此更改为自定义消息您将无法执行此操作

从Mozilla.org“注意,在Firefox 4和更高版本中,返回的字符串不会显示给用户。相反,Firefox会显示字符串“此页面要求您确认是否要离开-您输入的数据可能不会保存。”

更多信息:


请参阅错误:

有些浏览器可能会重复显示您的消息,有些则不会。这样做是为了防止欺诈或任何其他恼人行为。