I want to be able to detect when the mouse leaves the window so I can stop events from firing while the user's mouse is elsewhere.
Any ideas of how to do this?
I want to be able to detect when the mouse leaves the window so I can stop events from firing while the user's mouse is elsewhere.
Any ideas of how to do this?
In order to detect mouseleave without taking in account the scroll bar and the autcomplete field or inspect :
Conditions explanations:
Using the onMouseLeave event prevents bubbling and allows you to easily detect when the mouse leaves the browser window.
http://www.w3schools.com/jsref/event_onmouseleave.asp
I take back what i said. It is possible. I wrote this code, works perfectly.
works in chrome, firefox, opera. Aint tested in IE but assume it works.
edit. IE as always causes trouble. To make it work in IE, replace the events from window to document:
combine them for crossbrowser kick ass cursor detection o0 :P
If you are using jQuery then how about this short and sweet code -
This event will trigger whenever the mouse is not in your page as you want. Just change the function to do whatever you want.
And you could also use:
To trigger when the mouse enters back to the page again.
Source: https://stackoverflow.com/a/16029966/895724
I haven't tested this, but my instinct would be to do an OnMouseOut function call on the body tag.