Background: In Ajax applications, because the page is not refreshed, if the operation is on a page, the browser will not remember the status of each operation, which leads to a problem: after clicking a few times, the user wants to return to a previous click
The result (or directly want to go back to the result of the previous operation) will click the forward or back button of the browser, then the problem will come out. Because the URL has never changed, click the forward and backward buttons of the browser
Will not be what the user wants to see.
Existing implementations on the Internet: Gmail, Dropbox, Facebook, etc. (more and more applications are using this method)
1. Practice:
Write a timer to read the URL hash value (location. hash) (only the URL hash changes, which is called anchor in HTML), and then the corresponding display data is obtained based on the hash value changes.
2. Problem:
1. get location in Firefox. during hash, Firefox will automatically perform an additional decode, resulting in incorrect use of this value (You may say that it is decode once, And I encode it again <use JavaScript
Encodeuricomponent function> isn't it OK? The answer is no. Because Firefox only decode the values that can be Decode. If a URL hash contains a URL encoded like % 2B or % 25
Firefox will automatically decode it into another character, and the problem will arise ). For example, if the URL hash value at a certain time point is ABC % 25def and the location. hash value is used in Javascript
It is ABC % def. Obviously, the result is not what we want.
2. in IE 6 and 7, only the hash part of the URL changes, and the URL hash difference is not recorded in its history, which leads to the use of URL hash navigation in IE6, 7. Click the front or back button.
Will not get the expected results !!!
Solution:
1. it is quite clear that there are various ways to solve this problem (because our ultimate goal is to have a correct URL hash value, No matter what method is used, we certainly have a way to come up with such a result ), what is most commonly used is
The user replaces % with % URL encoding % 25 and decodes it once on the server, regardless of the browser. Always get a correct result (because % 25 is restored to % after decoding on the server ).
2. Now, you only know that you can add a hidden IFRAME to the page and remember the change records of the URL hash values under IE6 and 7 through IFRAME to achieve similar results. I don't know any other good solutions!