In this case, what you want is the event of when the user takes the mouse out of the window. For this you can use a solution like this:
Create a function that applies cross-browser mode event:
function addEvent(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}
And then apply the event to when the mouse output occurs in the window::
addEvent(document, "mouseout", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == "HTML") {
// Aqui você coloca o seu popup
alert("left window");
}
});
Below is the full sample code:
function addEvent(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}
addEvent(window,"load",function(e) {
addEvent(document, "mouseout", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (!from || from.nodeName == "HTML") {
// Aqui você coloca o seu popup
alert("left window");
}
});
});
I think it says something on this link: <a href="https://answall.com/questions/40982/display-algo-ao-tryingto close mysite"> https://answall.com/questions/40982/display-algo-ao-tryingto close mysite</a>
– isaque
You may like this https://answall.com/questions/229319/evento-tirar-o-mouse-da-janela/229356#229356
– user60252