themihai
themihai

Reputation: 8611

change URL link with javascript without refresh

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 .

Upvotes: 7

Views: 15329

Answers (1)

Tobias Krogh
Tobias Krogh

Reputation: 3932

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

Upvotes: 14

Related Questions