js在使用history.pushstate后设置默认URL

时间:2012-01-28 20:10:12

标签: javascript url history

我有问题。如何从history.pushState添加的网址“内容”中删除? 例如,我有一个这个网址:

site.com

好的,现在我将此网址更新为:

site.com/site/subsite

我如何恢复默认网址(site.com)。

我尝试history.pushState("",document.title,document.location.pathname)但是,

document.location.pathname是“site.com/site/subsite”

然后我回到起点:(

1 个答案:

答案 0 :(得分:5)

history.pushState("", document.title, "/");

它将完全从域url中删除状态。