Javascript – change URL link with javascript without refresh

browser-historyjavascript

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 .

Best Solution

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

in modern browsers that completely support the html5 history api you do:

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

EDIT: this dies not change the history of the browser

EDIT 2: just found this stackoverflow resource