如何在移动浏览器上检测退出意图?

时间:2022-07-05 05:46:00

I'm working on a solution to detect exit intent on safari mobile. (or any mobile browser for that matter)

我正在研究一种解决方案来检测safari mobile上的退出意图。 (或任何移动浏览器)

On desktop I can track curser movement and when the user breaks the plane of the webpage I can initiate a pop up. See http://www.quicksprout.com/about/ as an example. Move your curser up to the back button on the browser and as soon as your curser breaks the webpage a pop up will appear. How can I solve this in a mobile environment?

在桌面上我可以跟踪光标移动,当用户打破网页的平面时,我可以启动弹出窗口。以http://www.quicksprout.com/about/为例。将光标移动到浏览器上的后退按钮,一旦光标中断网页,就会出现弹出窗口。如何在移动环境中解决这个问题?

Is there any way to detect when someone clicks the Safari address bar and before the favorites screen appears I can launch a pop up then?

有没有办法检测有人点击Safari地址栏时,在收藏夹屏幕出现之前我可以启动弹出窗口?

Thank you in advance for the help.

提前感谢您的帮助。

2 个解决方案

#1


16  

I know this is over a year later, but maybe my answer might still help someone in the future.

我知道这是一年之后,但也许我的回答可能仍然会帮助将来的某个人。

On some of my sites, I found that mobile exit intent often consists of a slight upward scroll before the user hits their back button. For example, users often scroll down the page quite a bit while consuming content, but when they're ready to leave they might scroll upwards slightly (say 5-10% of the page height), and then they'll go hit the back button or close the tab.

在我的一些网站上,我发现移动出口意图通常包括在用户点击其后退按钮之前略微向上滚动。例如,用户经常在消耗内容的同时向下滚动页面,但是当他们准备离开时,他们可能会略微向上滚动(比如页面高度的5-10%),然后它们会被击中按钮或关闭选项卡。

I use that knowledge to pop up a newsletter sign up form on some of my content sites, and it actually works well without annoying the user. So if I ever detect that a user scrolled down at least 50% of my page, then back up by at least 5%, I hit them with a popup since I think they liked my content but are ready to exit the page. I wrote some simple Javascript that actually lets me detect such behavior at https://github.com/shahzam/DialogTriggerJS

我利用这些知识在我的一些内容网站上弹出简报注册表单,它实际上运行良好而不会让用户烦恼。因此,如果我检测到用户向下滚动了至少50%的页面,然后备份至少5%,我会弹出一个弹出窗口,因为我认为他们喜欢我的内容但是已准备好退出页面。我写了一些简单的Javascript,实际上让我在https://github.com/shahzam/DialogTriggerJS上检测到这种行为

Not sure if that's the exact answer you're looking for, but hope that helps a bit!

不确定这是否是您正在寻找的确切答案,但希望有所帮助!

#2


1  

At least on mobile safari, you're looking for the window.onpagehide function. This event will fire immediately after the page is hidden.

至少在移动游猎中,你正在寻找window.onpagehide功能。隐藏页面后,此事件将立即触发。

Here is a snippet showing this code in action:

以下是显示此代码的代码段:

<!DOCTYPE html>
<html>
    <head>
        <script> window.onpagehide = function(e) { alert("Don't go! I'm lonely!"); }</script>
    </head>
    <body>
    </body>
</html>

Unfortunately, it looks like if you want an event to fire before the page is hidden, you're out of luck, because mobile Safari halts execution of everything on the page when the user clicks on the address bar. This means that you cannot, for example, monitor the page height to see if the user is typing on the keyboard (as they would be if they clicked the address bar).

不幸的是,如果您希望在隐藏页面之前触发事件,那么您运气不好,因为当用户点击地址栏时,移动版Safari会停止执行页面上的所有内容。这意味着您不能,例如,监视页面高度,以查看用户是否在键盘上键入(就像他们点击地址栏时一样)。

#1


16  

I know this is over a year later, but maybe my answer might still help someone in the future.

我知道这是一年之后,但也许我的回答可能仍然会帮助将来的某个人。

On some of my sites, I found that mobile exit intent often consists of a slight upward scroll before the user hits their back button. For example, users often scroll down the page quite a bit while consuming content, but when they're ready to leave they might scroll upwards slightly (say 5-10% of the page height), and then they'll go hit the back button or close the tab.

在我的一些网站上,我发现移动出口意图通常包括在用户点击其后退按钮之前略微向上滚动。例如,用户经常在消耗内容的同时向下滚动页面,但是当他们准备离开时,他们可能会略微向上滚动(比如页面高度的5-10%),然后它们会被击中按钮或关闭选项卡。

I use that knowledge to pop up a newsletter sign up form on some of my content sites, and it actually works well without annoying the user. So if I ever detect that a user scrolled down at least 50% of my page, then back up by at least 5%, I hit them with a popup since I think they liked my content but are ready to exit the page. I wrote some simple Javascript that actually lets me detect such behavior at https://github.com/shahzam/DialogTriggerJS

我利用这些知识在我的一些内容网站上弹出简报注册表单,它实际上运行良好而不会让用户烦恼。因此,如果我检测到用户向下滚动了至少50%的页面,然后备份至少5%,我会弹出一个弹出窗口,因为我认为他们喜欢我的内容但是已准备好退出页面。我写了一些简单的Javascript,实际上让我在https://github.com/shahzam/DialogTriggerJS上检测到这种行为

Not sure if that's the exact answer you're looking for, but hope that helps a bit!

不确定这是否是您正在寻找的确切答案,但希望有所帮助!

#2


1  

At least on mobile safari, you're looking for the window.onpagehide function. This event will fire immediately after the page is hidden.

至少在移动游猎中,你正在寻找window.onpagehide功能。隐藏页面后,此事件将立即触发。

Here is a snippet showing this code in action:

以下是显示此代码的代码段:

<!DOCTYPE html>
<html>
    <head>
        <script> window.onpagehide = function(e) { alert("Don't go! I'm lonely!"); }</script>
    </head>
    <body>
    </body>
</html>

Unfortunately, it looks like if you want an event to fire before the page is hidden, you're out of luck, because mobile Safari halts execution of everything on the page when the user clicks on the address bar. This means that you cannot, for example, monitor the page height to see if the user is typing on the keyboard (as they would be if they clicked the address bar).

不幸的是,如果您希望在隐藏页面之前触发事件,那么您运气不好,因为当用户点击地址栏时,移动版Safari会停止执行页面上的所有内容。这意味着您不能,例如,监视页面高度,以查看用户是否在键盘上键入(就像他们点击地址栏时一样)。