支持使用 ajax 的浏览器后退按钮而不依赖于哈希更改?
我目前正在使用 jQuery BBQ 插件来启用 Bowser 导航按钮,但我有一个问题,如果用户为其中一个页面保存书签,比如说......
www.mysite.com/#page1
当用户通过书签返回时完整页面必须首先加载...
www.mysite.com/
然后 url 的哈希部分可用于 ajax 回调以完成页面。
为了解决这个问题,我尝试在对主页的所有 url 调用上仅创建一个“骨架”页面,以便通过 ajax 获取所有“内部”内容,但这似乎不是一个很好的解决方案。
有谁知道任何不使用“哈希”方法来支持“后退按钮历史记录”等的方法/插件?
I'm currently using the jQuery BBQ plugin to enable the bowser navigation buttons to work, but I have a problem in that if a bookmark is saved by a user for one of the pages, say...
www.mysite.com/#page1
when the user returns via the bookmark the full page has to first load...
www.mysite.com/
before the hash part of the url can be used for the ajax call back to complete the page.
To address the problem I've tried creating only a 'skeleton' page on all url calls to the main page so that all 'inner' content is fetched via ajax, but this doesn't seem a great solution.
Does anyone know of any methods/plugins that do not use the 'hash' method to support 'back-button history etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
防止双页加载的唯一解决方案是使用 HTML5 History API,它允许您直接修改 URL,而不必处理哈希值。
由于 HTML5 History API 相对较新,因此所有浏览器对它的支持都不同。您可以使用 History.js 规范浏览器之间的功能。
要了解有关哈希问题的更多信息,以及哈希与 HTML5 History API 的比较,请阅读 这篇文章。
The only solution to prevent that double page load is to use the HTML5 History API, which allows you to modify the URL directly, rather than having to deal with hashes.
As the HTML5 History API is relatively new, all browsers support it differently. You can use History.js to normalise the functionality between browsers.
To learn more about the problem you are having with hashes, and how hashes compare with the HTML5 History API, read this article.