Support browser back-button with ajax without relying on a hash change?

不打扰是莪最后的温柔 提交于 2019-12-05 04:13:26

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/6112989/support-browser-back-button-with-ajax-without-relying-on-a-hash-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!