在“pushstate”上正确更新浏览器地址字段
我通过ajax在网页中加载数据,并使用pushstate和popstate欺骗来更改浏览器地址字段。问题是我的ajax URL是这样的
2011/07/25/foo.txt
2011/07/26/bar.txt
2011/07/27/baz.txt
所以,第一次加载网页时,浏览器地址字段是http://webserver/
。第一次 ajax 加载时,它变成 http://webserver/2011/07/25/foo.txt
。在第二次 ajax 加载时,它变成 http://webserver/2011/07/25/2011/07/26/bar.txt
。在第三次 ajax 加载时,浏览器 URL 字段将变为 http://webserver/2011/07/25/2011/07/26/2011/07/27/baz.txt
。换句话说,只有地址字段的最后一个片段(在“/”上分割)被替换。
如何替换整个地址字段?
I am loading data in the web page via ajax, and using pushstate and popstate trickery to change the browser address field. The problem is that my ajax URLs are like so
2011/07/25/foo.txt
2011/07/26/bar.txt
2011/07/27/baz.txt
So, the first time the web page loads, the browser address field is http://webserver/
. On the first ajax load, it becomes http://webserver/2011/07/25/foo.txt
. On the second ajax load it becomes http://webserver/2011/07/25/2011/07/26/bar.txt
. On the third ajax load the browser URL field becomes http://webserver/2011/07/25/2011/07/26/2011/07/27/baz.txt
. In other words, only the last fragment of the address field (split on '/') gets replaced.
How can I replace the entire address field?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将前导
/
添加到推送路径。Add a leading
/
to the pushed path.