简体   繁体   English

onpopstate 事件不会在 Chrome/Safari 中触发

[英]onpopstate event doesn't trigger in Chrome/Safari

Chrome and Safari doesn't trigger the HTML5 onpopstate event. Chrome 和 Safari 不会触发 HTML5 onpopstate事件。 Here is my example:这是我的例子:

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

window.onpopstate() should fire on the initial page load, which counts as a history traversal. window.onpopstate()应该在初始页面加载时触发,这算作历史遍历。 See this WebKit bug , which has been resolved in recent WebKit builds.请参阅此 WebKit 错误,该错误已在最近的 WebKit 版本中得到解决。 (You code outputs HELLO as designed in Chrome 7.0.517.44, and presumably will do so in the next version of Safari.) (您按照 Chrome 7.0.517.44 中的设计对输出 HELLO 进行编码,并且可能会在下一版本的 Safari 中这样做。)

See also my (invalid) Chrome bug report for more discussion and links.另请参阅我的(无效)Chrome 错误报告以获取更多讨论和链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM