Javascript pageY issue with Microsoft Edge browser

2019-05-28 18:01发布

问题:

I want to create a simple script that will detect if user mouse leave window. Solution is already described here by using mouseout event. The problem with this solution is that it will trigger action also if user goes with mouse to scroller. So I added extra if condition e.pageY < jQuery(window).scrollTop() to this code:

addEvent(document, "mouseout", function(e) {
    e = e ? e : window.event;
    var from = e.relatedTarget || e.toElement;
    if ((!from || from.nodeName == "HTML") && e.pageY < jQuery(window).scrollTop()) {
        alert("left window");
    }
});

It works fine in all browsers, excepting Microsoft Edge. In Edge e.pageY won't be necessary 0 or -1,-2... as in other browsers but it will be 50,34,... (depends how fast you move mouse).

I am wondering if there is any simple solution to this problem.