I have this simple code that displays when user leaves or refreshes the page
<script>
var buttonClicked = false;
window.onbeforeunload = function () {
if (buttonClicked) {
buttonClicked = false;
}
else {
return "WARNING";
}
};
</script>
The buttonClicked
is true if user clicks on Next and the warning does not display.
When you click on reload, this warning still displays as expected, but clicking cancel still refreshes the page, losing all data entered in the form. This only happens in Google Chrome 77. I tried it on Firefox and Edge and this does not happen.
Strangely, when DevTools are open, Chrome does not refresh the page.
Is this a bug on there is something on my end that I got wrong?