admin管理员组文章数量:1287593
I am developing a system which is 100% ajax, except of course, the first request.
I am interested in changing the address in document.location, using javascript. But I don't want the browser to load the page on that "new" location.
Does anyone know how I can do this?
I am developing a system which is 100% ajax, except of course, the first request.
I am interested in changing the address in document.location, using javascript. But I don't want the browser to load the page on that "new" location.
Does anyone know how I can do this?
Share Improve this question edited Jul 3, 2013 at 16:11 Matt 23.8k18 gold badges74 silver badges116 bronze badges asked May 29, 2010 at 23:19 MiroMiro 1081 silver badge5 bronze badges 1- 1 why do you want to change the browser location address? If this is so that the user/Google can link into any page then just use regular HTTP requests. By using 100% AJAX you are creating a "single page site". There's pro's and cons to both regular HTTP and AJAX... I've always found a good bination of both of them is the best result. – scunliffe Commented May 29, 2010 at 23:59
3 Answers
Reset to default 7To rewrite the entire location and not just the "hash" part, browser history API can be used, although currently it only seems to be supported in Gecko 1.9.3/Firefox 4.
history.replaceState({}, document.title, url)
Changing the entire URL without navigating is not possible, just imagine the security issues that it could generate.
You can change only the location.hash
, which is the part of the URL that follows the #
symbol:
location.hash = "foo";
Your url will change to http://someurl./#foo
You can use the same method that Gmail uses. Append an anchor to the end of the url, the browser should not reload the page but you can read the information in document.location.href
and act on it. This also will keep the functionality of the back button intact (providing your javascript supports it)
for example
first page is http://www.mypage./index.php
you click to the next "page" using <a href="#page2">link</a>
and it changes to http://www.mypage./index.php#page2
本文标签: javascriptRewrite documentlocation without loadingStack Overflow
版权声明:本文标题:javascript - Rewrite document.location without loading - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741240600a2363898.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论