views:

58

answers:

2

I'm building a web app with jQuery & Rails. The web app loads pages with AJAX ... no page refresh.

When a user clicks on a link to load a new page via AJAX, i want to update the address bar. I also want to maintain the browser's back button support.

ideas?

A: 
  1. Link to e.g. #page1 or #page2; this will keep you on the same page
  2. Bind a function to these links that retrieves the window.location.hash
  3. Load the relevant data, depending on the retrieved hash info
Alec
so update the URL to a HASH.... but then if that gets bookmarked, how does the browser know what to do with /#projects for example?
WozPoz
Call on the same function when the document is finished loading (using jQuery's `$(document).ready()` e.g.). That way it sees that the page was loaded with the hash `#projects`, and it'll update the page accordingly.
Alec
+2  A: 

I had the same demand on a project, this feature is called Deep link.

You just have to use a jQuery plugin called Address http://www.asual.com/jquery/address/, it makes everything easy. There is a wonderful documentation and examples on the site.

Thiago Diniz