How to intercept back button in Sammy.js

798 Views Asked by At

I´m currently using Sammy.js in my Single Page Application and want to notify the user if he tries to leave a site with changed content.

Is it somehow possible to intercept the back command or any other routing change to display some hint before?

1

There are 1 best solutions below

0
On

See my answer here for one way to do what you're looking for. The group I work for actively uses this technique to show a dialog whenever a user tries to navigate away from a page that has been modified but not saved.

Outside of the solution I point out there, you cannot prevent the back button from actually navigating them. If you could do that with JavaScript, that could be easily abused to keep users on a page until they closed the browser.