
Browser back button not working without user interact in the web page
Hi,
I need help resolving an issue related to browser navigation and the popstate event.
Here's the scenario:
- The user starts on page-1.html.
- They click a button, which navigates to page-2.html.
- When the user presses the browser back button (without clicking any button on the page), I want to trigger a JavaScript popstate event automatically.
Currently, I'm doing the following:
- When the user arrives at page-2.html from page-1.html, I show a popup.
- When the user closes the popup, I manually push a state using history.pushState() to create a backward URL entry.
However, my client’s requirement is to trigger the popstate event without requiring any user interaction on page-2.html, i.e., as soon as the user presses the back button.
Is there a way to programmatically achieve this behavior (ensuring the popstate event is fired) without requiring the user to click anything on page-2.html?
Any guidance or recommended approach would be greatly appreciated.
Thank you.