Reputation: 2803
I'm using anchors for dealing with unique urls for an ajaxy website. However, I want to reload the content when the user hits the Browser's "back" button so the contents always matches the url.
How can I achieve this? Is there a jQuery event triggering when user clicks "Back"?
Upvotes: 2
Views: 1286
Reputation: 1454
YUI history manager does this by checking the hash every 10ms using setInterval. There is no event registered by back, so that is probably the only way possible.
Upvotes: 0
Reputation: 3167
You need to use a hashchange event. There are a couple of popular plugins. I've been using the address plugin and like it. Some will suggest BBQ also.
Upvotes: 1
Reputation: 630607
If you're using ajax urls and not reloading the page, I'm guessing you have #something
style URLs, using hash navigation. If that's the case you probably want the window.onhashchange
event to reload the appropriate content.
Since it's not supported by all browsers, there's a plugin for this, your code would look something like this:
$(window).hashchange(function() {
//do something with location.hash that just changed
});
Upvotes: 1