views:

41

answers:

1

I was on Facebook and realised that when I change page the page address changes but the page does not redirect but loads via ajax instead.

You can tell because the console does not clear when you click the link but the URL changes.

Weird, but anyone know how it is done?

A: 

Facebook runs with massive AJAX calls that changes the page state and the sections. So to make a page linkable to somebody by copying the URL address, every time you call an AJAX relevant function they updates the URL using a fake anchor "#!" plus the real address. Simply when you load the real page (using F5 or linking that so somebody) a JS parser catchs the string after #! (if there is) and redirect you to baseaddress + that.

I belive something like this (untested):

var urlstr = new String(location.href);
var urlparm = urlstr.split('#!');
var last = urlparm.length - 1;

if( (urlparm[last] != urlparm[0]) && (urlparm[last] != "/") )
{  var redir = "http://www.facebook.com" + urlparm[last];
   location.href = redir;
}

In Google Chrome instead the URL really changes, I'm according that there is an hash somewhere, but I don't know where and how.

Fabio M.
Ahh, you're right. Google chrome removes the hash!
ITg
If Chrome is doing that, then they're breaking anticipated functionality
drachenstern
Yeh, Google rule the web now :P
ITg