Matthew Simoneau
Matthew Simoneau

Reputation: 6279

How do I refresh content in the page and update the URL without doing a full page reload?

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?

Upvotes: 0

Views: 523

Answers (1)

PatrikAkerstrand
PatrikAkerstrand

Reputation: 45721

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.

Upvotes: 4

Related Questions