1

I am using history.pushState to manipulate the browser history, Is there a way to undo/pop a particular pushed state.

Let's say I came from google.com to myPage.com. After an ajax call I do pushState,

window.history.pushState({}, "SUMMARY", "/summary.html"); 

Now after some more ajax calls, Is there a way to delete the earlier pushed state so the back button takes me to google.com instead of myPage.com

Edit: After the first ajax call I am pushing the state so i can go back earlier state, but I want to remove this functionality if another ajax call is made .

matrixguy
  • 286
  • 1
  • 6
  • 30

2 Answers2

0

You can use replaceState

window.history.replaceState({}, "", "https://google.com"); 
gurvinder372
  • 66,980
  • 10
  • 72
  • 94
0

When you are loading content using AJAX call then instead of pushState you can use replaceState . replaceState does not manipulate the browser's history, it simply replaces the current URL in the address bar. Upon hitting the back button you'll find that we don't return to the replaced URL but instead you'll go back to whatever page we were on before.

In your case you can use

window.history.replaceState({}, "SUMMARY", "/summary.html"); 
Tanmay
  • 1,123
  • 1
  • 10
  • 20