鍍金池/ 問答/HTML/ 為什么onbeforeunload,總是返回默認(rèn)的語句 ,怎么自定義的不起作用呢

為什么onbeforeunload,總是返回默認(rèn)的語句 ,怎么自定義的不起作用呢?

window.onbeforeunload = function (e) {
        var message = '正在排隊(duì)中,請勿關(guān)閉瀏覽器';
        e = e || window.event;
    
        if (e) {
            e.returnValue = message;
        }
    
        return message;
    };
window.onbeforeunload = function (e) {
  e = e || window.event;

  // 兼容IE8和Firefox 4之前的版本
  if (e) {
    e.returnValue = '正在排隊(duì)中,請勿關(guān)閉瀏覽器';
  }

  // Chrome, Safari, Firefox 4+, Opera 12+ , IE 9+
  return '正在排隊(duì)中,請勿關(guān)閉瀏覽器';
};
<body onbeforeunload="return myfunction()">
 
<script>
function myfunction() {
    return "正在排隊(duì)中,請勿關(guān)閉瀏覽器";
}
</script>

這三種方式都不行,只顯示瀏覽器的默認(rèn)提示“確定要離開.....” ie,chrome,360,edge都不能顯示自定義的內(nèi)容呀?

回答
編輯回答
薄荷糖

你的上一個(gè)問題,不是有人已經(jīng)告訴你了。新版本的瀏覽器 beforeunload 不會(huì)再展示自定義的內(nèi)容。

從Firefox 4、 Chrome 51、Opera 38 和Safari 9.1開始,通用確認(rèn)信息會(huì)代替事件返回的字符串。
2017年5月25日 14:06