简体   繁体   中英

How to intercept back button in Sammy.js

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM