How To Change Url Without Changing Browser History

how to change url without changing browser history

Tags: javascript , html , browser-history Answers: 1 | Viewed 25,118 times



Until now, I only know that if I want to change URL without reloading the whole page i have to use HTML browser history API.


I am using this concept in my website. Let's take example. Let suppose user is on this page


 https://www.example.com/aboutus

and then he goes to product listing in which we have filters. On clicking any filters system generates new url something like this


https://www.example.com/products?brands[]=song&brands[]=samsung&condition[]=new

Internally it is just calling


history.pushState({}, 'Title', link.href);

But, it has one problem. Clicking back button takes to the previous filter. I dont want this functionality. I want , on clicking browser back button it should take to the page which is before current page. In our case, it is suppose to take to


https://www.example.com/aboutus

Thanks.


Some Answers For How To Change Url Without Changing Browser History

#1. how to change url without changing browser history

1 Answer. You're looking for replaceState (), it replaces the current position in the history instead of pushing a new one, like pushState () does. history.replaceState () operates exactly like …


 https://www.example.com/aboutus 

https://www.example.com/products?brands[]=song&brands[]=samsung&condition[]=new 

history.pushState({}, 'Title', link.href);

https://www.example.com/aboutus 

history.replaceState({}, 'Title', link.href);

#2. [Solved] how to change url without changing browser history

Oct 14, 2021  · You're looking for replaceState(), it replaces the current position in the history instead of pushing a new one, like pushState() does. history.replaceState({}, 'Title', link.href); …


history.replaceState({}, 'Title', link.href);

 https://www.example.com/aboutus 

https://www.example.com/products?brands[]=song&brands[]=samsung&condition[]=new 

history.pushState({}, 'Title', link.href);

https://www.example.com/aboutus 

#3. How to change browser url without changing anything in …

Aug 21, 2015  · Stack Overflow Public questions & answers; Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers; Talent Build your …


// add to storage localStorage.setItem('myAttibute', 'acceptable');
// Retrieve the object from storage (on another page) var sMyAttibute= localStorage.getItem('myAttibute');
alert("myAttibute=" + sMyAttibute);

#4. how to change url without changing browser history - CodeForDev

Web You're looking for replaceState(), it replaces the current position in the history instead of pushing a new one, like pushState() does. history.replaceState({}, 'Title', link.href); from …


history.replaceState({}, 'Title', link.href);

Please leave your answer here: