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 exit in the window:
addEvent (document, "mouseout", function (e) {
e = e? e: window.event;
var from = e.relatedTarget || e.toElement;
if (! from || from.nodeName == "HTML") {
// Here you put your popup
alert ("left window");
}
});
Here is the complete 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");
}
});
});