0

Possible Duplicate:
How does facebook rewrite the source URL of a page in the browser address bar?

Maybe this is a silly question, and I apologize if it's a simple one, but I'm not sure if I'm getting the terminology correct so I haven't been able to find any results with google.

I'm looking to change/modify the current page's URL (or specifically it's GET variables) using AJAX. I didn't think this was at all possible but it appears to be done in Facebook.

For instance when I'm on my facebook profile the url is written:
http://www.facebook.com/profile.php?id=xxxxx&sk=wall

Then if I click on the info link below my profile picture it changes to:
http://www.facebook.com/profile.php?id=xxxxx&sk=info

And there is no page refresh (as far as I can see).

So what's the deal, how is this done?

Community
  • 1
  • 1
Barak Gall
  • 1,422
  • 12
  • 24
  • 3
    See http://stackoverflow.com/questions/3849758/how-does-facebook-rewrite-the-source-url-of-a-page-in-the-browser-address-bar – Crescent Fresh Mar 10 '11 at 01:14

2 Answers2

0

AFAIK you cannot change the URL without a refresh except to add a hashtag anchor. You can use the location.replace method:

http://www.w3schools.com/jsref/met_loc_replace.asp

Updated to reflect @Crescent Fresh's link

Looks like there is another option with HTML 5's history.pushState() (currently only supported by Webkit):

How does facebook rewrite the source URL of a page in the browser address bar?

Community
  • 1
  • 1
Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
  • I don't think that this is what facebook does. Firstly there is no hash in the link as you can see and unless I'm just missing it, I really don't see any refresh. I'm about to go through the source and try to figure it out. But if anyone already knows the answer please post it. – Barak Gall Mar 10 '11 at 01:09
  • Wrong; see http://stackoverflow.com/questions/3849758/how-does-facebook-rewrite-the-source-url-of-a-page-in-the-browser-address-bar – Lightness Races in Orbit Mar 10 '11 at 01:30
  • I'd make Tomalak's response the answer but it's just a comment. Thanks you guys. – Barak Gall Mar 10 '11 at 03:21
0

The page URL query-string cannot be modified without a new request, but its "fragment identifier" (the part after the #) can, with javascript (thus Ajax).

You can even leverage that using ScriptManager's EnableHistory property.

<asp:ScriptManager ID="ScriptManager1" runat="server" EnableHistory="true" onnavigate="ScriptManager1_Navigate" />

and

protected void Button_Click(object sender, EventArgs e)
{
   //Do something.
   // ...

   //Then "remember the state".
   ScriptManager1.AddHistoryPoint("SomeState", "SomeStateValue"); 
}

protected void ScriptManager1_Navigate(object sender, HistoryEventArgs e)
{
  //Get the state back.
  String statevalue = e.State["SomeState"];
  // ...
}
tiago2014
  • 3,392
  • 1
  • 21
  • 28