views:

125

answers:

1

I thought that JavaScript didn't allow you to update the browser's URL (for bookmarking, etc) without doing a full page refresh. Facebook seems to accomplish this in their photos application, though. When I click "next" to see the next photo, the new photo loads and the URL updates, but the whole page doesn't refresh. Does anyone know how they accomplish this?

+4  A: 

They don't update the URL per se, they only update the Hash (i.e # followed by instructions). The hash is never sent to the server, but can be used to go to anchor points in the DOM (built in browser functionality), or used as a hook for JavaScript. Upon page load with a hash variable set, they send an Ajax-request to fetch the corresponding photo. The initial page load will, however, load the picture indicated by the url before the #-character.

PatrikAkerstrand
I always wondered about their crazy URLs, with the anchor in the middle of them. Now I understand some of the motivation. Thanks!
Matthew Simoneau