Is it possible to display a custom message in the beforeunload popup?

后端 未结 5 2315
眼角桃花
眼角桃花 2020-11-22 06:30

When using window.onbeforeunload (or $(window).on(\"beforeonload\")), is it possible to display a custom message in that popup?

Maybe a sma

5条回答
  •  太阳男子
    2020-11-22 07:25

    All the above doesn't work in chrome at least it need to add return false otherwise nothing happen.

    window.onbeforeunload = function(e) {
      $('#leaveWarning').show();
    
      // the timer is only to let the message box disappear after the user
      // decides to stay on this page
      // set this to 1ms .. since timers are stopped for this modal  
      setTimeout(function() {
        $('#leaveWarning').hide();
      }, 1);
    
      // 
      return false;
      return "This message is not relevant in most modern browsers.";
    }
    

提交回复
热议问题