5

I have this sample code for tracking if back button of the browser is pressed. The code works with IE , Firefox and Safari on computer. When I checked the code with Safari on Ipad, the .confirm dialog is not shown when I press the back button. I've tested with Safari 9 on iOS 9.3. Settings of Safari allows popup.

I have no idea how to make the code works on Ipad Safari. Has anyone same problem?

<html>
<head>
</head>
<body>
    <script src="jquery-3.1.0.js"></script>
    <script>
        jQuery(document).ready(function ($) {
            if (window.history && window.history.pushState) {
                window.history.pushState(null, null, $(location).attr('href'));

                $(window).on('popstate', function () {
                    $("#lblMessage").html("Onpopstate");                        

                    if (!confirm('Browse back?'))
                        window.history.pushState(null, null, $(location).attr('href'));
                    else 
                        window.history.back();
                });
            }
        });
    </script>

    <div id="lblMessage">Status
    </div>
</body>

I created a test site here.

T N
  • 396
  • 5
  • 13
  • I think this is the same problem as https://stackoverflow.com/questions/38083702/why-are-alert-confirm-and-prompt-not-working-after-using-js-history-api – AlpineCarver May 27 '17 at 21:55

0 Answers0