我想知道如何从网址中删除该ID。 像这样:完全删除网址中的散列
页面链接:
http://www.exampledomain.com/index.html#example
当用户点击它变成了链接:
http://www.exampledomain.com/index.html
我想知道如何从网址中删除该ID。 像这样:完全删除网址中的散列
页面链接:
http://www.exampledomain.com/index.html#example
当用户点击它变成了链接:
http://www.exampledomain.com/index.html
有几种方法来此,根据您的具体环境。
如果你只是想删除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),但那些正在迅速消失。
location.hash工作,谢谢! – 2014-09-24 14:33:28
如果只有ie8 *会*迅速消失..... – andrew 2014-09-24 14:37:11
非常欢迎。不要忘记[接受你最喜欢的问题的答案](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
你可能可以用重定向来做到这一点,但这是一种混乱。 – 2014-09-24 14:25:59