window.onpopstate,event.state == null? [英] window.onpopstate, event.state == null?
问题描述
null
我知道它不适用于jQuery事件,但是当我做这样的事情时:
window.onpopstate = function(e){
console.log(e.state)
}
沿着jQuery.ajax成功调用的某些行
history.pushState ({lastUrl:data.State},data.Title,data.UrlKey);
Chrome(v19)或Firefox(v12)都不会返回任何内容,而是返回null?我错过了什么吗?它是不是完全实现?
e.state
指推后的第二个状态。你需要为 e.state
至少两次推送状态,而不是 null
。这是因为您应该在第一次加载站点时以及之后每次更改状态时保存状态。
So I've read several question/answers on stackoverflow and googled the issue, I cant seem to get the event.state to come back with anything but null
I got that it wont work with the jQuery event, but when I do something like this:
window.onpopstate = function (e) {
console.log(e.state)
}
With something along the lines of a jQuery.ajax success calling
history.pushState({ lastUrl: data.State }, data.Title, data.UrlKey);
Neither Chrome (v19) or Firefox (v12) return anything but null? Am I missing something? Is it just not fully implemented?
e.state
refers to the second last state that was pushed. You need to have pushed state at least twice for e.state
to not be null
. This is because you should save the state when your site is loaded the first time and thereafter every time it changes state.
这篇关于window.onpopstate,event.state == null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!