2014-09-24 82 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