简体   繁体   English

退出网页时弹出消息

[英]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...所以我们可以将一些 Javascript 绑定到这些网页上的链接,但是我们无法控制用户是否通过输入 URL、使用书签或只是关闭窗口来退出网页......

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.如果用户尝试关闭浏览器窗口,我认为我们的选择有限……但我知道这是可能的,因为如果您在关闭浏览器时有未保存的工作,Google Docs 的文档提供了取消关闭窗口的机会。

What are my options?我有哪些选择? Can I have Javascript called upon going to another webpage?我可以在转到另一个网页时调用 Javascript 吗? 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.我正在使用 jQuery,所以如果有使用 jQuery 实现的好的解决方案,那就太好了。

There is onunload event you can bind to, first example:您可以绑定到 onunload 事件,第一个示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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