I work on a website where the url parameter is updated based on user action, according to which I refresh the web page without updating. Consider an e-commerce scenario where the URL changes when a user clicks on filters and then updated products are displayed.
Now the problem is that when the user clicks the back button of the browser, the browser returns to the previous url parameter, but the page does not change. I want to change the page also based on the url parameter, which changes after clicking the back button.
I tried this solution:
$($window).on('popstate', function (e) {
The problem with this code is that it starts as url changes, means that it doesnโt need the browser button to be clicked, or the URL is changed using jQuery. Therefore, if I change the url based on user interaction, the popstate callback and my user function will be called. To refresh the page, I use https requests, so the HTTP api is called twice.
Is there a way to check if only the back button is pressed?
source share