Organizational Research By

Surprising Reserch Topic

detecting back button hash change in url

detecting back button hash change in url  using -'javascript,ajax,navigation,fragment-identifier,hashchange'

I just set up my new homepage at  I'm using jQuery, but very minimally.
It loads all the pages using AJAX - I have it set up to allow bookmarking by detecting the hash in the URL.  

 //general functions
 function getUrl(u) {
      return u + '.html';
 function loadURL(u)    {
      $.get(getUrl(u), function(r){
 //allows bookmarking
 var hash = new String(document.location).indexOf("#");
 if(hash > 0)
      page = new String(document.location).substring(hash + 1);
      if(page.length > 1)

But I can't get the back and forward buttons to work.  

Is there a way to detect when the back button has been pressed (or detect when the hash changes) without using a setInterval loop?  When I tried those with .2 and 1 second timeouts, it pegged my CPU.

asked Sep 16, 2015 by mtabakade
0 votes

Related Hot Questions

Government Jobs Opening