how to change url in browser url box?

匿名 (未验证) 提交于 2019-12-03 01:00:01

问题:

I really wonder why facebook and google can change the url without reloading the page? they just change the block or content in their site.

I notice that when I am using facebook, when click on the "new feed" the url is "http://www.facebook.com/" and the page didn't reload, then i click on "messages" the url changed to "http://www.facebook.com/messages/" and the page still not reload just change the "content" block of the site.

So how do I change url without reloading the page?

edit: i got the answer.
there are 2 cases here:

hope this help to who have doubt like me.

回答1:

Have you looked into the history API for Javascript?

http://diveintohtml5.ep.io/history.html

EDIT: You could also use mod_rewrite with apache and then, but that would cause a refresh.

Or there is this JQuery Plugin

http://www.asual.com/jquery/address/



回答2:

The URL usually changes to http://facebook/#!messages, so the change of the "fragment" URL part doesn't make the browser reload the page. Instead, there is some JavaScript library that watches fragment changes and make appropriate requests in order to reload the page content.

The usage of #! is almost becoming a "standard" for doing these things, I've seen this used elsewhere (eg. on Twitter). I don't remember if they all use the same library or just the naming convention, but you should be able to dig about it on the fb/twitter developers pages.



回答3:

You could look into the Content-Location HTTP header for this purpose. See here for more info.



回答4:

I code on JSBin.com, mainly use CSS and HTML (Abandoned Javascript loooong time ago) and have a question. For example a page's URL is http://www.codingrules.com/ Well, using HTML, How can I change that URL to for example http://www.ilovecoding.com



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!