saving history in ajax

2019-08-02 13:31发布

问题:

I am using ajax in my site. When a user enters a query and selects a category, I update the page with server fetched content using ajax. In addition I update the URL with a hash value which shows the query and the category separated by a &.

What I want to do is to make it so when the browser back-button is pressed I want to display the previous result without reloading.

What I am getting is that URL that has the previous values, but the result is not updating. How can I change that? Can any one help me?

回答1:

The short answer would be use the #hash part of the uri, this part if updated doesn't refresh the page, and in most browsers makes a history checkpoint, however by saying in most browsers, means that no support in IE6, and I think IE7. The other way is when you detect IE, you can embed a 1 pixel iframe and set it's source to a page on your domain, and make your javascript sets its ? part of the url so the page refreshes, and in this case IE will save history point. This problem is solved in IE8

Example

http://codinginparadise.org/weblog/2005/08/ajax-tutorial-tale-of-two-iframes-or.html