2014-09-24 84 views

回答

1

有幾種方法來此,根據您的具體環境。

如果你只是想刪除hash值:

location.hash = ''; 

...但是這葉的位置#。 (這也滾動用戶在頁面的頂部。)取消:

location = location.pathname; 

...但是這將刷新頁面,太。爲了解決所有這些問題:

history.pushState({},'',location.pathname); 
    // back button returns to #example 

history.replaceState({},'',location.pathname); 
    // back button doesn't return to #example 

...其中isn't supported in some old browsers(包括IE 9),但那些正在迅速消失。

+0

location.hash工作,謝謝! – 2014-09-24 14:33:28

+0

如果只有ie8 *會*迅速消失..... – andrew 2014-09-24 14:37:11

+0

非常歡迎。不要忘記[接受你最喜歡的問題的答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work),並在未來嘗試[分享如果可以的話,你已經嘗試過](http://stackoverflow.com/help/how-to-ask)。 – Blazemonger 2014-09-24 14:37:43