6

I would like to display an image when the user clicks the back button of the browser. The code below worked fine in safari 15.5, but when I upgraded to safari 16.1, it did not work. Popstate not working in safari 16.1?

<!doctype html>
<html>
  <head>
    <meta charset="utf-8">
    <script>
      history.replaceState(null, null, null)
      history.pushState(null, null, null);
      window.addEventListener('popstate', function () {
        alert('fired');
      });
    </script>
  </head>
  <body>test</body>
</html>

I confirmed that when I clicked the browser back button in safari 15, the alert message was displayed. When I ran it in safari 16, nothing was executed and the previous page was displayed as is.

nowa
  • 61
  • 2
  • 1
    I've found that if you long-press on the back button in Safari and choose the first entry from the list, it works as it used to for previous versions (Safari 15 & 14). – eddiewould Dec 08 '22 at 03:04
  • See https://bugs.webkit.org/show_bug.cgi?id=248303 (no response from the WebKit team on that yet) – sideshowbarker Dec 27 '22 at 07:17

1 Answers1

0

In my case, I had some async scripts in HTML and some browser abilities were blocked until those scripts loaded completely.

mseyfayi
  • 116
  • 5