AJAX and back button

烂漫一生 提交于 2019-12-06 14:27:16

Github and Google+ are using history.pushState.

You can change the current url like this:

history.pushState(null, null, '/the-new-url');

This is supported by Firefox, Chrome, Opera, Safari; not IE.

See https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history#The_pushState%28%29.c2.a0method

There are basically two options when it comes to AJAX and history.

  1. The # method (which isn't a hack btw). Since you don't want that one you only have option 2 left.

  2. Use PushState. This is what Facebook, GitHub and a few others use. It's not supported by all browsers though and if you want complete cross-browser compatibility you will have to use a system which can degrade to option 1.

A very simple way to implement this is Backbone.js Router class.

There is a simple jQuery hashchange plugin that is designed to solve this specific problem.

I haven't used it; I don't know how it keeps track of the url history.

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