如何在鼠标指针悬停在浏览器的关闭按钮上时检测事件? [英] how to detect the event when the mouse pointer is over the close button of the browser?

查看:368
本文介绍了如何在鼠标指针悬停在浏览器的关闭按钮上时检测事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

换句话说,当鼠标指针悬停在浏览器的关闭按钮(X按钮)上时,这是用于检测事件的javascript / jquery代码



或当鼠标指针进入浏览器的X按钮时。

obs:类似的东西( http ://www.jpost.com ),进入网站并将

鼠标指针放在浏览器的关闭按钮(X按钮)中。

in other words, which is the javascript/jquery code used to detect the event
when the mouse pointer is over the close button (X-button) of the browser,
or when the mouse pointer is enter the X-button of the browser.
obs: something like (http://www.jpost.com), enter the site and put the
mouse pointer in the close button(X-button) of the browser.

推荐答案

这称为退出意图。

您无法在文档外跟踪用户鼠标移动。 />
但是你可以检查鼠标输出运动矢量是什么,并预测它是否意图关闭或其他东西

That is called exit intent.
You cannot track user mouse movement outside document.
But you can check on mouse out what was the movement vector and predict if it was intent to close or something else

跟踪退出意图的简化版本

Simplified version of tracking exit intent

https://jsfiddle.net/kristapsv/qs3wk8Ld /

var addEvent = function(obj, evt, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evt, fn, false);
  }
  else if (obj.attachEvent) {
    obj.attachEvent("on" + evt, fn);
  }
};

addEvent(document, "mouseout", function(event) {
  event = event ? event : window.event;
  var from = event.relatedTarget || event.toElement;
  if ( (!from || from.nodeName == "HTML") && event.clientY <= 100 ) {
    alert("left top bar");
  }
});

这篇关于如何在鼠标指针悬停在浏览器的关闭按钮上时检测事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆