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.

- 69
- 1
- 4
-
What are you trying to accomplish? – Michael Liu Apr 22 '15 at 20:24
-
something like (http://www.jpost.com), enter the site and put the mouse pointer in the close button(X-button) of the browser. – wltsta Apr 23 '15 at 04:44
3 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");
}
});

- 558
- 5
- 15
-
I have put and tested your code in the window.onload event, whit corrections – wltsta Apr 23 '15 at 19:59
-
-
-
Hi @Kristapsv That worked for me. But when I bring the mouse over the close window and tab, it should give me an alert at that time only. I have use your logic but it is executing whenever I bring the mouse over the "minimize", "restore down", "close", or whenever I hover the mouse over the tab. I want the logic to execute only on first mouse hover over close window and tab. It should not repeat whenever I hover the mouse over the close window/tab. – Ambika Tewari Sep 17 '18 at 07:33
-
Hey, @AmbikaTewari as zfrisch mentioned in his answer and comment there is no possible way to track user interaction outside document and it's nearly impossible to guess what user will do outside document based on his mouse movement. Only way to guess that is to track and log user movement patterns and analyse which ones led to closed window and later when you have enough data you could predict if users intends to close the window, but this is different topic. – Kristapsv Sep 21 '18 at 11:27
There isn't one. That would be a very dangerous set of events to have available via the web.

- 8,474
- 1
- 22
- 34
-
-
as was suggested by Kristaps you can't track movement outside of the document. You can guess based on mouse movement or can implement plugins for that functionality. Keep in mind that there are flaws, for instance if your mouse starts outside of the DOM and enters after page load, it'll most likely trigger. For more in depth information check out this previous post http://stackoverflow.com/questions/24016658/detect-exit-intent-with-jquery Keep in mind this isn't a site for us to write your code for you, it's for assistance. – zfrisch Apr 23 '15 at 20:27
After reading your question, I was curious, and I searched online. I found that the ouibounce
library was suggested. This doesn't explicitly check if a user is hovering over the browser exit icon, but it does allow you to display a modal/popup before a user attempts to leave your website.
Below are example steps you can follow to use this library:
1) Create a modal. i.e. <div id="modal"></div>
2) Select the modal. i.e. var modal = getElementById('modal');
3) Call outibounce on the selected modal. i.e. var bounce = ouibounce(modal);
4) Fire or disable the ouibounce. i.e. bounce.fire();
Take a look at the ouibounce
github for more info. This is where I found out about ouibounce by searching online for questions related to yours.