Start New Discussion within our Web Development Community

Hi,
A site I'm developing loads new pages via AJAX, to allow people to share the links we use a hashtag to track the URL E.G.
User is on example.com/page1.html
User clicks on link to example.com/page2.html
page2.html is loaded dynamically and the URL is set to example.com/page1.html#!/page2.html
That all works fine, but now when the user presses the 'Back' button in their browser the URL changes to example.com/page1.html but the page stays the same. Is there any way to do something similar to

document.onBackButton = function() {
   //Check hashtag and load new page
}
document.onForwardButton = function() {
   //Check hashtag and load new page
}

Thanks
-Sam

The article starter has earned a lot of community kudos, and such articles offer a bounty for quality replies.