1

I use window.history.pushState to change the current URL when I open a popup on my page, which works well and is very convenient. Inside the popup I can go to other URLs. The problem is when I close the popup i use pushState again with the first URL, but if press back, it opens the popup again.

What I want is that pressing Back after closing the popup goes back to the previous page before opening the popup.

Home -> Page -> Popup 1 -> Popup 2 -> (Close popup) Page -> (Press back) Home (instead of Popup 2)

ariel
  • 15,620
  • 12
  • 61
  • 73
  • Check [my answer](http://stackoverflow.com/questions/20156939/how-to-handle-back-button-while-changing-the-browser-url-with-html5-pushstate/20157851#20157851) on this post which, unlike you, doesn't talk about a popup but an object literal with your popup identifier helps you to conditionally check on `popstate` if you press back on the popup. – Tim Vermaelen Apr 20 '14 at 10:59

1 Answers1

0

What I did was using history.go(-x) instead of doing pushState(originalURL).

Home -> (normal navigation) Page -> (pushstate) Popup 1 -> (pushstate + increase popup count) Popup 2 -> (Close popup + go(-2)) Page -> (Press back) Home

EDIT

After doing this i see that most browsers have a limit of the history size (on chrome is 50). So I changed to replaceState when moving from popup 1 to 2.

Home -> (normal navigation) Page -> (pushstate) Popup 1 -> (replacestate) Popup 2 -> (Close popup + go(-1)) Page -> (Press back) Home

This will also close the popup when pressing back.

ariel
  • 15,620
  • 12
  • 61
  • 73