I'm using the following function (found in this really helpful post) to detect whether the mouse left the window :
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 (e)
{
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == "HTML")
{
console.log("left the window");
}
});
However, this is not working when the mouse leaves the window really slowly or when the mouse is really close to the border of the window right before it leaves the window.
Is there a way around that, using either jQuery or pure Javascript?