admin管理员组文章数量:1301603
I'm currently working in a AJAX oriented web application. I have been looking for the different ways of replicating the current AJAX state (or Application state) with the browsers url so refreshing and back-button also works.
In the last weeks I see different approaches involving the use of the hash (#) and different JS-frameworks.
In the documentation it is stated, that changing the browsers URL from JS is not possible. Today I went to Facebook and opened an image, and the url changed (Altough the image was opened in a lightbox). After the image was closed, the browser url changed back to the original page.
Do you have any idea how they achieve this behavior?
I'm currently working in a AJAX oriented web application. I have been looking for the different ways of replicating the current AJAX state (or Application state) with the browsers url so refreshing and back-button also works.
In the last weeks I see different approaches involving the use of the hash (#) and different JS-frameworks.
In the documentation it is stated, that changing the browsers URL from JS is not possible. Today I went to Facebook and opened an image, and the url changed (Altough the image was opened in a lightbox). After the image was closed, the browser url changed back to the original page.
Do you have any idea how they achieve this behavior?
Share Improve this question asked May 5, 2011 at 15:24 NicolasNicolas 1862 silver badges15 bronze badges 4- 2 possible duplicate of How is Github Changing Pages and the URL so smoothly without AJAX? – Quentin Commented May 5, 2011 at 15:27
- 1 Not a duplicate, but good for supplemental information: What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for? – Jeremy Commented May 5, 2011 at 15:29
- @DAvid Thanks for the hint! I think thats a good place to start looking for this! Great help! – Nicolas Commented May 5, 2011 at 15:48
- 3 possible duplicate of Facebook and Ajax – ifaour Commented May 5, 2011 at 18:32
3 Answers
Reset to default 7There is a feature of HTML5 that supports what you are referring to. See http://spoiledmilk.dk/blog/html5-changing-the-browser-url-without-refreshing-page.
Some systems implement this by checking for window.history.pushState, and if so, using it, otherwise falling back to hashtags. If SEO is of concern, use #! instead of #. See http://code.google./intl/es/web/ajaxcrawling/docs/getting-started.html.
Hope that helps.
You are able to manipulate the has value at the end of the URL like this:
var hashVal = 'somevalue';
window.location.hash = '#' + hashVal;
And then the url will bee www.something./#somevalue
You can manipulate the hash value as Neal pointed out. But i would remend using a library for doing the same. Here's one that i use
http://developer.yahoo./yui/history/
Hash values in the URL are manipulated mainly for back button and bookmark integration. Hope this helps.
本文标签: ajaxChange URL from Javascript like facebook doesStack Overflow
版权声明:本文标题:ajax - Change URL from Javascript like facebook does - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741673872a2391766.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论