gpt4 book ai didi

javascript - 退出调查弹出窗口

转载 作者:行者123 更新时间:2023-11-30 18:57:19 25 4
gpt4 key购买 nike

我正在尝试创建一个退出弹出窗口来对我正在工作的网站进行退出调查。我遇到的最常见的解决方案是捕获页面的 onunload 事件,并向所有链接点击事件添加事件处理程序以阻止弹出。

示例:http://www.pgrs.net/2008/1/30/popup-when-leaving-website

这种方法有几个问题:

首先,您将无法检测到页面刷新或手动 URL 更改等事件,因为这是浏览器事件而不是页面事件。

其次,如果用户打开多个选项卡并关闭一个选项卡,则无法判断用户仍在网站上。即使我们使用 cookie 来跟踪打开的窗口数量,我们也不知道用户是真的离开网站,还是只是转到内部链接。

我觉得我可以实现的最佳解决方案是覆盖所有事件和跟踪在 cookie 中打开的窗口的组合,但我想知道是否有人提出了更好的方法。

最佳答案

你无法解决这个问题。

First, you will not be able to detect events such as a page refresh or a manual URL change, since it's a browser event and not a page event.

实际上,我希望所有这些东西仍然会触发 onunload,尽管我不是 100% 确定。如果他们不这样做,我会感到惊讶。

Secondly, if the user has multiple tabs open and closes one, it's impossible to tell that the user is still on the site. Even if we use cookies to keep track of number of windows open, we won't know if the user is actually leaving the website, or just going to an internal link.

是的。除非你为此付出巨大的努力,否则你无法解决它。什么是巨大的努力?见过 gmail 吗?它如何在你登录的任何地方显示你在底部,以及远程踢人的能力?诸如此类,页面对服务器执行 ping 操作,服务器保持状态和持续通信。

关于javascript - 退出调查弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1544271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com