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
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;
});