Javascript : Change current URL without redirecting the page

Sometimes, we need to change the url of current page without redirecting the page to the another url. Using javascript , we can achieve this very easily.

We can use the location object and its different properties to create our new url and using window object we can easily replace the current url with the new one.

Here is the example using which we can perform it :

<scrript type=”text/javascript”>

var clean_uri = location.protocol + “//” + + location.pathname;

window.history.replaceState({}, document.title, clean_uri);


Thus, using above two line of code, we can change the url of any page without refreshing or redirecting it.

Leave a Reply