Internet Explorer 10 and popstate not binding

故事扮演 提交于 2019-12-04 23:47:43

问题


I was wondering what could cause window.addEventListner('popstate', foo, false) window.attachEvent('onpopstate', foo) and window.onpopstate=foo to not trigger the function foo. We have code similar to this and in production it does not fire but in development it does. Is it possible to disable the popstate event via JS or cause some sort of collision or race condition for this to occur?

EDIT (Gustin): + Sample Code

PopStateEvent.js (complete listing, using jQuery 1.9.1):

$(window).bind('popstate', function () { alert("Pop state event received!"); });

If I'm testing this very simple example with IE 10 (10.0.9200.16484), I never receive a pop state event (i.e. the alert box never appears). Not even if I navigate away and come back via the back button of IE. I.e. this Q/A doesn't solve my case.

With Chrome 24, everything works fine.


回答1:


Are you sure that you aren't calling it using history.pushState() or history.replaceState()?

popstate is only triggered when you do something with the browser, like the back button , or called using history.back().

other than that, it will work with chrome because it'll shoot a popstate when the page is loaded, so check to make sure the event is actually being loaded. Checking for this should be included in the :

if (document.readyState == "complete") {
    initApplication();
}

I believe popstate is included in document.readyState, so give it a shot.



来源:https://stackoverflow.com/questions/14698299/internet-explorer-10-and-popstate-not-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!