Is it possible to rewrite the URL in the URL-field on the client's browser?
So when a person clicks on a link on my page something ajax happens (eg a tab shows up) i want the url to display the action without refreshing the page.
Is this possible?
the page using JavaScript? the page using JavaScript? Method 2: Adding a new state with pushState() Method: The pushState() method is used to add a new history entry with the properties passed as parameters. This will change the current URL to the new state given without reloading the page.
history. pushState(nextState, nextTitle, nextURL); // This will replace the current entry in the browser's history, without reloading window.
In fact, JavaScript provides the location object, a part of the window object, which allows you to perform different URL-related operations.
When everyone else answered this question, they were right, it wasn't possible to change the URL in javascript. With HTML5 and modern browsers, it now is using the HTML5 History API
diveintohtml5.info article about it. Here is another good blog post explaining the feature.
Check caniuse.com for browser compatability.
There are libraries such as History.js which wrap the API and pollyfill using hashbangs for old browsers.
You can change the hash/anchor part of the URL (after #). The rest of the URL is readonly.
location.hash = "#value";
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