2012-01-28 35 views
4

我遇到問題。我如何從URL中刪除「內容」由history.pushState添加? 例如我有這個網址:js使用history.pushstate後設置默認網址

site.com 

好了,現在我更新此網址到這一點:

site.com/site/subsite 

我怎樣才能恢復默認的URL(site.com)。

我嘗試history.pushState("",document.title,document.location.pathname)但是,

document.location.pathname是 「site.com/site/subsite」

,我回到起點:(

回答

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

它將從完全刪除狀態域名網址。