简体   繁体   中英

Popup a message upon exiting a webpage

We'd like to have a message popup when a visitor to specific webpages leave those webpages. So we could tie some Javascript to the links on those webpages, but then we can't control if the user exited the webpage by typing in a URL, using a bookmark or just closing the window...

I assume we have limited options if the user tries closing the browser window... but I do know it's possible because Google Docs' Documents offers the chance to cancel closing the window if you have unsaved work while closing the browser.

What are my options? Can I have Javascript called upon going to another webpage? Can I control the text in the popup when trying to close the window?

I'm using jQuery, so if there are good solutions implemented with jQuery that's perfectly fine.

There is onunload event you can bind to, first example:

http://www.codetoad.com/javascript/miscellaneous/onunload_event.asp

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