beforeunload on IE 11 - do not prompt user does not work

后端 未结 1 588
予麋鹿
予麋鹿 2021-02-19 17:17

When adding a listener to the global window object for the beforeunload event, IE 11 (and 10) does not behave as Chrome and Firefox.

Normally, you return a

相关标签:
1条回答
  • 2021-02-19 17:37

    The solution is not to return anything (which is the same as return; or return undefined;).

    var isDirty = false;
    var message = '** You have unsaved changes. **'
    window.addEventListener('beforeunload', function(evt){
      if(isDirty) {
        evt.returnValue = message;
        return message;
      }
      delete evt.returnValue;
    });
    
    0 讨论(0)
提交回复
热议问题