I have the following code in my Vue
application for detecting when the user closes the tab:
onBeforeUnload() {
window.onbeforeunload = null;
return undefined;
}
Disabling the "Leave page" confirmation dialog works in Chrome, but not on Firefox. Why is that? How do I disable the confirmation dialog on Firefox?
Edit 1: Adding and removing beforeunload
listeners
created() {
window.addEventListener('beforeunload', this.onBeforeUnload);
},
beforeDestroy() {
window.removeEventListener('beforeunload', this.onBeforeUnload);
}
Changing my onBeforeUnload
method to this fixed the problem:
onBeforeUnload(e) {
window.onbeforeunload = () => {};
delete e.returnValue;
}