onbeforeunload event processing problems on Windows 10 in Chrome and Edge

103 views Asked by At

I'm using onbeforeunload event handler to trigger browser dialog "Do you really want to exit" in case user did some data entry.

Up till lately it worked without problems, but lately browsers (latest version of Chrome and Edge, Windows 10) gets in a strange loop before asking the question. It moves browser window several times, each time a bit to the left and up, until it reaches upper left corner. Only then it asks the question. There is no such problem in Firefox.

This is my simple test code:

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
</head>

<body>
  <input id="1" type="radio" onchange="change()">
  <label for="1">Test</label>
<script>
  var changed = false;
  
  function change() {
    changed = true;
  }
  
  window.onbeforeunload = function (e) {
    if (changed) {
      e.preventDefault();
      e.returnValue = true;
    }
  };
</script>
</body>

</html>

And this is how browser looks during this strange moving process:

enter image description here

Is this a bug or there was some change in how this event should be processed in Chrome an Edge?

0

There are 0 answers