哪一个是好pushstate或的location.hash? [英] Which one is better pushstate or location.hash?

查看:158
本文介绍了哪一个是好pushstate或的location.hash?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

window.location.hash VS HTML5 history.pushstate 。其中哪一个是更好地满足URL与Ajax请求,为什么? 谢谢你。

window.location.hash vs HTML5 history.pushstate. Which one of these would be better to meet the url with the ajax request and why? Thanks.

推荐答案

的location.hash 具有比一个更好的支持<一href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState%28%29.C2.A0method#Browser_compatibility"><$c$c>history.pushState方法。
pushState 方法的优点是可以的状态结合到的历史记录条目。
如果您不需要这个状态对象,我建议使用的location.hash 财产,与旧的浏览器更好的兼容性。

location.hash has a better support than the history.pushState method.
The advantage of the pushState method is that you can bind a state to the history entry.
If you don't need this state object, I recommend to use the location.hash property, to have a better compatibility with older browsers.

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"}

这篇关于哪一个是好pushstate或的location.hash?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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