<script type="text/javascript"> window.addEventListener('beforeunload', function (e) { e.preventDefault(); e.returnValue = ''; }); </script> code example
Example: js before unload
window.addEventListener('beforeunload', (event) => {
// Cancel the event as stated by the standard.
event.preventDefault();
// Chrome requires returnValue to be set.
event.returnValue = '';
});