so say I set a hash when i do an ajax call:
example: http://example.com/#hash.html
if I load another page and click on the backbutton, how would i detect the hash and extract the url on load? The rest I got already covered :).
If you need more code, please tell me. btw, i'm using jquery.
Simple example using window.location.hash to load appropriate hash content set in url while navigating back and forth.
Hope this helps someone...cheers!!
If you've wired up your navigation properly the page loaded into your content element should already be there since the browser had to navigate to that #hash
There is an event,
hashchange
, but it's only supported in Firefox 3.6, IE8 and I assume the latest Chromes and Safaris.For best support, detect the
hashchange
event, and if not present, use a polling function withsetInterval()
.So you would do something like...
You have a couple of options.
The most obvious one is
...which has been part of actual JavaScript for some years (more information here or by googling "javascript location hash").
There is also a jQuery plugin called jQuery.Url which has a lot of nice features for working with URLs.