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);

更多相关文章

  1. 从事件监听器OnClick中排除按钮
  2. jQuery在点击按钮上迭代/循环遍历数据表
  3. 如何在用户选择操作后获取当前日期和时间
  4. 如何使用带有“IF”条件的按钮改变DIV的背景颜色
  5. 如何检索类以隐藏按钮?
  6. Jquery禁用/启用按钮与文本框代码
  7. js和jquery使按钮失效为不可用状态的方法
  8. fullcalendar.js - 在按钮点击时删除事件
  9. 如何让代码等待好/取消按钮选择?

随机推荐

  1. Android内部存储和外部存储
  2. Android(安卓)工程中各种文件的介绍
  3. Android 白板代码实现
  4. Android 应用间跳转
  5. Android DNK安装笔记
  6. Android利用TextView制作跑马灯该效果
  7. Android(安卓)获取屏幕尺寸与密度
  8. Android 面试总结之布局常见问题
  9. Android中一个Activity多个intent-filter
  10. Android部分控件的特殊属性