Questions tagged [popstate]

Use this tag for questions regarding the "popstate" DOM window event that is fired when the active history item changes, and its related event handler "onpopstate".

The popstate DOM window event is fired when the active history item changes. This happens, for example, when the user clicks the browser's back button. Use this tag for questions related to this event and its related event handler onpopstate.

Resources

Related Tags

127 questions
33
votes
2 answers

Chrome popstate not firing on Back Button if no user interaction

I'm trying to use "pushState" and the "popstate" event to trap Back button navigation, however, while the popstate event triggers correctly in Firefox, it doesn't trigger in Chrome (Version 76.0.3809.87 (Official Build) (64-bit)) if there is no user…
Praemon
  • 606
  • 1
  • 7
  • 9
25
votes
5 answers

Can I prevent history.popstate from triggering on initial page-load?

I'm working on a site that serves content via AJAX. If you click an item in the menu, a content div gets updated with $.get response, nothing fancy. I'm implementing history.pushState to allow navigation with the browser's back/forward button. I…
jassa
  • 19,123
  • 4
  • 24
  • 24
22
votes
2 answers

PJAX: Problems with back button

Some our links are wrapped by PJAX. When a user clicks on a PJAX link the server returns only the required part of the HTML. If I do the following: Click PJAX link Click simple link Press back button the browser will display content that was…
fedor.belov
  • 19,444
  • 25
  • 79
  • 121
16
votes
2 answers

Is it possible to e.preventDefault in window.onPopState?

I'm trying to stop the user from going back in my web app. For this I tried catching the window.onpopstate and added e.preventDefault to cancel the back button effect. But it doesn't seems to happen. window.addEventListener('popstate',function(e){…
Ivin Jose
  • 3,405
  • 7
  • 38
  • 60
16
votes
1 answer

window.onpopstate is not working; nothing happens when I navigate back to page

I'm trying to add window.onpopstate on one of the pages on my site, but nothing is happening. I put this script on the page: