加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ajax – 哪一个更好的pushstate或location.hash?

发布时间:2020-12-16 03:10:33 所属栏目:百科 来源:网络整理
导读:window.location.hash vs HTML5 history.pushstate。哪一个会更好地满足与ajax请求的url,为什么? 谢谢。 location.hash 比 history.pushState 方法有更好的支持。 pushState方法的优点是您可以将状态绑定到历史记录条目。 如果您不需要此状态对象,我建议
window.location.hash vs HTML5 history.pushstate。哪一个会更好地满足与ajax请求的url,为什么?
谢谢。
location.hashhistory.pushState方法有更好的支持。
pushState方法的优点是您可以将状态绑定到历史记录条目。
如果您不需要此状态对象,我建议使用location.hash属性,以更好地兼容旧版浏览器。
location.hash = 'new-hash';
console.log(history.state); // null or undefined

history.pushState({extraData: "some state info"},'','new-hash'); //<---
console.log(history.state); // [object Object] = {"extraData": "some state info"}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读