PDA

View Full Version : Detecting Mouse Leaving Page



Trinithis
08-09-2007, 03:12 AM
I have a mousedown event that turns a variable "resizing" to true, and a mouseup event that sets it to false. I want the "resizing" variable to be set false when the user moves his mouse out of the page into the "menu/bookmarks/scrollbar/statusbar/etc part of the browser" or completely out of the browser.

I want to do this because if the mouse is released over these areas, my JS won't detect it when the mouse is brought back into the page, and it will still think my resizing script is still taking place.

NOTE: This script might only work in FF, but that is not an issue for my purposes (at least so far).

Code:
http://trinithis.awardspace.com/resize/resize.js

Demo:
You should be able to resize the squares like desktop windows.
http://trinithis.awardspace.com/resize/testWindow.html

jscheuer1
08-09-2007, 07:13 AM
This might work out:


onmouseout=function(e){
if(!e.relatedTarget)
stop whatever
};

Trinithis
08-09-2007, 06:36 PM
Thanks, it works perfectly.