Ipad - popstate中的window.confirm函数无法正常工作

时间:2016-08-25 11:52:28

标签: ipad safari confirm popstate

我有这个示例代码,用于跟踪是否按下了浏览器的后退按钮。该代码适用于计算机上的IE,Firefox和Safari。当我在Ipad上使用Safari检查代码时,按下后退按钮时不显示.confirm对话框。我在iOS 9.3上使用Safari 9进行了测试。 Safari的设置允许弹出窗口。

我不知道如何让代码在Ipad Safari上运行。有没有同样的问题?

<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>

我创建了一个测试网站here

0 个答案:

没有答案