Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于onpopstate #34

Open
xinglie opened this issue Aug 17, 2016 · 0 comments
Open

关于onpopstate #34

xinglie opened this issue Aug 17, 2016 · 0 comments

Comments

@xinglie
Copy link
Owner

xinglie commented Aug 17, 2016

Magix第1个版本做了hash与pushState之间的切换兼容
关于url解析可以看这篇

当时在做history.pushState时(2012年),发现对于onpopstate对于不同的浏览器是不一样的。

$(window).on("popstate", function() {
    alert('popstate');
});

上述代码在chrome中页面加载完成时竟然会弹出 popstate
现在仍然能够搜出很多在stackoverflow问这个问题的人,如
http://stackoverflow.com/questions/4688164/window-bind-popstate
http://stackoverflow.com/questions/6421769/popstate-on-pages-load-in-chrome/

当时阅读了pjax,使用了类似如下的解决方案

var initialURL = location.href,popped
$(window).bind('popstate', function(event) {
  var initialPop = !popped && location.href == initialURL
  popped = true
  if ( initialPop ) return

当然,现在并没有这样的问题了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant