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.


I've never attempted to do this, but it seems like this has been discussed on the internet.

Here looks to be a good place to start:

+9  A: 

Use the jQuery history plugin instead. Regarding your full ajax navigation, try to have SEO friendly ajax. Otherwise your pages shown nothing in browsers with JavaScript limitations.

The history plugin worked, and thanks for the link on SEO.
Tom Ritter

I used a jquery plugin and wrote a YUI History like interface on top of it.

Check it out once. If you need help I can help

+4  A: 

jQuery BBQ (Back Button & Query Library)

A high quality hash-based browser history plugin and very much up-to-date (Jan 26, 2010) as of this writing (jQuery 1.4.1).

+1  A: 

Another great implementation is balupton's jQuery History which will use the native onhashchange event if it is supported by the browser, if not it will use an iframe or interval appropriatly for the browser to ensure all the expected functionality is successfully emulated. It also provides a nice interface to bind to certain states.

Another project worth noting as well is jQuery Ajaxy which is pretty much an extension for jQuery History to add ajax to the mix. As when you start using ajax with hashes it get's quite complicated!