如何检测用户有关退出页面的信息?
I would like to detect when a user is about to exit the page, before they click the back button, and do something - for example display a popup. I do not want to prevent the user from leaving the page, but only to grab their attention again.
我想检测用户何时即将退出页面,然后再单击后退按钮,然后执行某些操作 - 例如显示弹出窗口。我不想阻止用户离开页面,只是为了再次引起他们的注意。
This is already done by Optin Monster, but I want to implement it myself.
这已经由Optin Monster完成,但我想自己实现它。
Where to start?
从哪儿开始?
Edit: beforeunload
is fired after the user clicked the back or x button. I would like to catch his exit intent, for example when the mouse is moving towards the back button, but before it was clicked.
编辑:在用户单击后退或x按钮后触发beforeunload。我想捕捉他的退出意图,例如当鼠标朝向后退按钮移动时,但是在它被点击之前。
3 个解决方案
#1
18
Ouibounce does this. There is a live demo here.
Ouibounce这样做。这里有现场演示。
npm install ouibounce
Then:
var ouibounce = require('ouibounce');
var modal = document.getElementById('ouibounce-modal')
ouibounce(modal);
更多相关文章
- 从事件监听器OnClick中排除按钮
- jQuery在点击按钮上迭代/循环遍历数据表
- 如何在用户选择操作后获取当前日期和时间
- 如何使用带有“IF”条件的按钮改变DIV的背景颜色
- 如何检索类以隐藏按钮?
- Jquery禁用/启用按钮与文本框代码
- js和jquery使按钮失效为不可用状态的方法
- fullcalendar.js - 在按钮点击时删除事件
- 如何让代码等待好/取消按钮选择?