jquery - JavaScript Historic back/forward -
i'm building little coffeescript application 10 buttons , container (simple). when user press on 1 of button : container change.
the buttons navbar , instead of using links (that reload entire page), used javascript (coffeescript, jquery or whatever) change content of page (with ajax query load data).
the problem , forward button of browser can't work solution... , need find solution that. routing maybe ?
i way asana.com resolved issue: address change content seems not entirely reloaded.
what suggest ? help
hashes. simplest solution define url hash every time user clicks on button. example:
location.href = "#" + button.id;
with that, create history entry, , user can press or forward in browser.
but how can check when happens? there's hashchange
event:
window.onhashchange = function() { var state = location.hash.substring(1); // chomps initial # ... };
basing code on state
variable, can trigger ajax calls there.
by way, can change code altogether, using links instead of buttons hash href
property, not reload page, creates history entry , fires hashchange
event.
the hashchange
event supported every modern browser (that support history.pushstate
too, more flexible , powerful way control history) , ie8-9.
Comments
Post a Comment