Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check if the mouse exited the browser window using javascript/jquery?

I need a way to check and see if the mouse is outside the browser window. The problem is that the mouseout event (or mousemove) isn't triggered when the mouse RAPIDLY moves outside the the browser window (my element is close to the edge). I figured the best way to solve my problem is to check on a timer if the mouse is inside the window or not, but I haven't found a way to do that, since I need an event to fire in order to get the mouse coordinates.

I'm a javascript/jquery newbie, but it seems like there should be a way to do this but I definitely haven't been able to find it so far. Maybe I could force a mouse event to trigger and see if there's any xy value? Any idea how I could do that?

Thanks in advance!

like image 558
Sabrina Leggett Avatar asked Jan 15 '12 21:01

Sabrina Leggett


People also ask

How do you check if the mouse is over an element in Javascript?

Use document. elementFromPoint(x, y) method to get the element content on that position when mouse pointer moves over.

Can Javascript control mouse?

You can't move the mouse pointer using javascript, and thus for obvious security reasons. The best way to achieve this effect would be to actually place the control under the mouse pointer.

What is Mouseout in jQuery?

jQuery mouseout() MethodThe mouseout event occurs when the mouse pointer leaves the selected element. The mouseout() method triggers the mouseout event, or attaches a function to run when a mouseout event occurs.


1 Answers

Seems like @Joshua Mills solved this problem here:

  • How can I detect when the mouse leaves the window?

Although it was never officially selected as an answer.

like image 185
Ayman Safadi Avatar answered Nov 15 '22 00:11

Ayman Safadi