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.