Because this does not work:
window.addEventListener('beforeunload', function(){
return 'wait a minute'
})
And this works:
window.onbeforeunload = function(){
return 'wait a minute'
}
Are not they the same thing?
Because this does not work:
window.addEventListener('beforeunload', function(){
return 'wait a minute'
})
And this works:
window.onbeforeunload = function(){
return 'wait a minute'
}
Are not they the same thing?
The two do not work the same way. The addEventListener
with event beforeunload
requires event.returnValue
:
window.addEventListener('beforeunload', function(event){
var mensagem = "wait a minute";
event.returnValue = mensagem;
return mensagem;
});
More information this MDN document in English .