views:

174

answers:

4

how can i controls #! in url suppose i have the following url

http://www.facebook.com/#!/video/video.php?v=1106030301789

now how facebook controls that #! in url....

+3  A: 

http://googlewebmastercentral.blogspot.com/2009/10/proposal-for-making-ajax-crawlable.html - this might explain a little about it :-)

Alex
A: 

The short answer is: via Ajax

Ajax allows main page to dynamically load content without need to refresh page

PiotrK
If the URL in the address bar is changing, it's not Ajax.
Rushyo
The URL is changed in the normal way, with links changing the anchor/hash. An event listener sees the change and calls the ajax.
meleyal
A: 

The # symbol in a URL is a special character with a reserved meaning. When the browser sees the #, it treats that as the end of the actual URL, and anything after it is treated as a label; the browser will look for that label and jump to the point in the page where it finds it.

Therefore the URL you have supplied won't work. It will just go to the Facebook home page.

If you need to have a URL with a # in it, you will need to URL-encode it. But then it won't be a # any more.

Having said all that, Javascript can see the whole URL, including the # symbol and the label after it, so a page could have Javascript on it which reads that and loads the required content via Ajax.

Spudley
+1  A: 

Take a look at sammy.js

$.sammy(function() {

  this.get('#/', function() {
    $('#main').text('Welcome!');
  });

});

Or route.js

route('#/Learn').bind(function(){ 
    Alert('Alert1'); 
}); 

There's also a standards way to do it with the new popstate event in html5

meleyal