使用javascript更改URL链接而不刷新

问题描述:

是否可以在不刷新页面的情况下自动将url example.com/4000/title-2/#!4000更改为example.com/4000/title-2?基本上是从URL中删除/#!4000。
注意在hashbang之前删除/并不仅仅是hashbang很重要。

Is it possible to automatically change the url example.com/4000/title-2/#!4000 to example.com/4000/title-2 without to refresh the page ? Basically to remove "/#!4000" from the URL. Note that is important to remove the "/" before the hashbang not just the hashbang .

不知道是否这对你来说已经足够了,它是否完全可以跨浏览器工作...... chrome接受:

dont know if it is enough for you and whether it works completely cross-browser... chrome accepts:

location.hash = "";

但这会在地址栏中保留#

but this keeps the "#" in the address bar

window.history.replaceState('Object', 'Title', '/4000/title-2');

编辑:这不会改变浏览器的历史记录

this dies not change the history of the browser

编辑2:刚刚找到此stackoverflow资源