Mozilla firefox not working with [removed]

前端 未结 4 644
清酒与你
清酒与你 2020-11-30 11:35

I\'m using window.onbeforeunload to display a message to the user on windows close, the function works well with Chrome and IE but it doesn\'t work with Firefox

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-30 12:21

    Using the code given in the MDN works for me in firefox/chrome/IE11 (haven't try other browser for now).

    window.onbeforeunload = function (e) {
      var e = e || window.event;
    
      // For IE and Firefox
      if (e) {
        e.returnValue = 'Any string';
      }
    
      // For Safari
      return 'Any string';
    };
    

    here is the doc : Mdn window.onbeforeunload doc

提交回复
热议问题