0

Does anyone know how to show a confirmation alert to user on go back or go forward buttons of browser clicked?

I tried to use popstate event but it does not show an alert to user. Then I added an confitmation alert on popstate event but even if the user cancel the alert it goes back. I found I can use history.forward() inside on cancel event but what it does is just refreshing the page but I do not want to refresh the page because I don’t want to lose any information. Please help.

  • 1
    I think this issue already been discussed and have good solution to it. https://stackoverflow.com/a/25806609/4233425 – Rahad Rahman Dec 17 '22 at 17:40

0 Answers0