window.onpopstate,event.state == null? [英] window.onpopstate, event.state == null?

查看:104
本文介绍了window.onpopstate,event.state == null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经阅读了几个关于stackoverflow的问题和答案,并且搜索了这个问题,我似乎无法得到event.state,只能返回 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆