'beforeunload' Chrome Issue

前端 未结 6 1951
不思量自难忘°
不思量自难忘° 2021-02-07 08:40

I have this simple piece of code -

$(window).bind(\'beforeunload\', function(){
    alert(\"Good Bye\")
});

Works great with Firefox, IE8 but

6条回答
  •  余生分开走
    2021-02-07 08:47

    Try this for all Browsers:-

    window.addEventListener("beforeunload", function (e) {
    
      var confirmationMessage = "\o/";     
      e.returnValue = confirmationMessage;           
      return confirmationMessage;       
    
    });
    

提交回复
热议问题