【问题标题】:onpopstate event doesn't trigger in Chrome/Safarionpopstate 事件不会在 Chrome/Safari 中触发
【发布时间】:2011-04-22 20:11:21
【问题描述】:

Chrome 和 Safari 不会触发 HTML5 onpopstate 事件。 这是我的例子:

<!doctype html> 
<html> 
    <head> 
        <title></title> 
        <script src="http://code.jquery.com/jquery-latest.js"></script> 
        <script> 
            window.onpopstate = function(e) {
                document.getElementById("log").innerHTML = "HELLO";
            }
            $(function() {
                $("a").click(function(e) {
                    e.preventDefault();
                    window.history.pushState({page: $(this).index()}, $(this).html(), $(this).attr('href'));
                });
            });
        </script> 
    </head> 
    <body> 
        <a href="new-state">Foo</a> 
        <a href="other-state">Hallo</a> 
        <div id="log"></div> 
    </body> 
</html>

【问题讨论】:

    标签: jquery html google-chrome safari jquery-events


    【解决方案1】:

    window.onpopstate() 应该在初始页面加载时触发,这算作历史遍历。请参阅this WebKit bug,这已在最近的 WebKit 版本中得到解决。 (您按照 Chrome 7.0.517.44 中的设计编码输出 HELLO,并且可能会在下一个版本的 Safari 中这样做。)

    有关更多讨论和链接,另请参阅 my (invalid) Chrome bug report

    【讨论】:

    猜你喜欢
    • 2019-01-14
    • 1970-01-01
    • 2020-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-08
    相关资源
    最近更新 更多