1window.addEventListener('beforeunload', (event) => {
2 // Cancel the event as stated by the standard.
3 event.preventDefault();
4 // Chrome requires returnValue to be set.
5 event.returnValue = '';
6});
1window.addEventListener("beforeunload", function(event) { ... });
2window.onbeforeunload = function(event) { ... };