本文介绍了我如何检测用户关于退出页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想检测用户何时要退出该页面,在点击后退按钮之前执行某项操作 - 例如显示弹出式窗口。我不想阻止用户离开页面,但只是为了再次抓住他们的注意力。

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.

从哪里开始?

编辑:
beforeunload 在用户点击后退或x按钮后被触发。我想赶上他的退出意图,例如当鼠标移向后退按钮,但在点击之前。

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.

推荐答案

可以做到这一点。这里有。

Ouibounce does this. There is a live demo here.

npm install ouibounce

然后:

Then:

var ouibounce = require('ouibounce');
var modal = document.getElementById('ouibounce-modal')
ouibounce(modal);

这篇关于我如何检测用户关于退出页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 18:55