Smart way to manage browser history

I am trying to implement decent navigation in an AJAX application. Now I am doing the following:

  • Each time a user clicks on an AJAX link, a corresponding call is made and the hash is changed.
  • Whenever a new page loads, I check to see if a hash is present and make an appropriate AJAX call to refresh the page. This ensures that bookmarks will work as expected.
  • Every 500 ms, I check if the hash has changed, and make the appropriate AJAX call. This ensures that users press the back / forward buttons, albeit with a delay in merging.

The third point is a bit annoying: I would prefer not to have a timeout every 500 ms to check the hash, since most of the time it will remain the same.

Is there a better way to handle this? I can’t come up with any alternatives, but maybe something is missing.

Please do not point me to ready-made solutions if you do not know that they are based on a different mechanism.

+5
source share
3 answers

There is a hashchange event that must be implemented in HTML5. I'm not sure how good support is now ... IE8 supports it, and I think Mozilla has its own implementation in a recent release. Other than that, I'm not afraid of anything. Exx x ms validation is the way everyone does it.

+5
source

, , . , , hashchange (: ie),

0

: http://www.asual.com/jquery/address/

JQuery Address , - . , :

0
source

All Articles