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 .
There is no way to modify the URL in the browser without reloading the page. The URL represents what the last loaded page was. If you change it ( document. location ) then it will reload the page.
location to Redirect to a Different URL with JavaScript. You can redirect a web page to another page in a number of ways including server-side redirects, HTML meta refresh redirects and JavaScript redirects.
Ideally pushState() is used to change the URL seen in the browser's address bar; while popstate is executed once a user hits 'Back' in their browser. The example below will simply modify the URL of the given page. However, this method can only modify locations within the same domain.
pushState() method # The history. pushState() method can be used to push a new entry into the browser's history—and as a result, update the displayed URL—without refreshing the page.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With