【问题标题】:Detecting what is causing page exit检测导致页面退出的原因
【发布时间】:2018-03-15 19:55:24
【问题描述】:

我知道(使用 Jquery)您无法使用 beforeUnload 事件检测到您的页面何时因任何原因即将卸载

例如

$(window).on('beforeUnload' , function ( e ) {
            return "please dont leave";
});

是否有可能检测到这是否是由页面之外的东西引起的,例如关闭选项卡/窗口或使用后退/前进按钮。

如果无法正常检测到此类事物的使用,是否可以确定 beforeUnload 不是由任何 DOM 元素上的任何事件触发的?

【问题讨论】:

  • 请问您需要做什么?

标签: javascript jquery onbeforeunload exit-intent


【解决方案1】:

不容易检测浏览器操作等外部操作, 你可以做相反的事情。

示例 - 跟踪是否是链接

 var el = null;
    $('a,.submit-button,.other-exit-buttons').click(function(e){
    el=e;
    });

$(window).on('beforeUnload' , function ( e ) {
            console.log(el);
            // do other stuff like log it
            return "please dont leave";
});

因此,您可以检查用户是否退出抛出锚标记,或者您可以使用此方法跟踪所有退出“提交”按钮。

映射您的主要退出事件,而不是所有站点,如果用户退出并且您的 var 仍然为“null”,则您知道该用户以另一种方式退出。

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-01-12
  • 1970-01-01
  • 2014-02-17
  • 1970-01-01
  • 2016-06-28
  • 1970-01-01
相关资源
最近更新 更多