Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to detect the event when the mouse pointer is over the close button of the browser? [closed]

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.

like image 214
wltsta Avatar asked Dec 15 '22 15:12

wltsta


1 Answers

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");
  }
});
like image 118
Kristapsv Avatar answered May 19 '23 17:05

Kristapsv