Search code examples
javascriptbackbone.jsbrowser-history

Get the last hash after the hash has changed


I have a backbone app where I want to open an overlay which is just a page with its own URL. You can also navigate in this overlay with different pages/URLs. So when the overlay is closed I want to set back the hash to the state before the overlay was opened. As the overlay is opened by a link I can't get the hash from the state before.

So is there a way to get the previous hash when a hash changed?


Solution

  • The hashchange event has a "oldURL" field.... store all the "oldURL" (or only the last one) and, when you need it, change the actual url with the last url.

    Source: https://developer.mozilla.org/en/DOM/window.onhashchange