Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

body mouseout is called for each element

Status
Not open for further replies.

y2k1981

Programmer
Aug 2, 2002
773
0
0
IE
I want to detect when the mouse laves the main window of the doucmnet, ie goes up to the toolbar, or down to the status bar etc. I've added an onmouseout to the body tag, but it's begin called each time I mouse over an element in the document, eg a div or a table. I haven't tried it with inline elements such as anchor tags etc, but why is it being called at all at this point. Shouldn't it just be called when the mouse leaves the body, after all the body contains all those elements so the mouse is still in there.

can anybody help at all ... PLEASE
 

Shouldn't it just be called when the mouse leaves the body

You would have thought so, given that the name is "onmouseout"... But it does fire when the mouse is no longer directly over the body... And when the mouse is over an element, it is not directly over the body... so the event fires.

Dan

 
Thanks Billy Ray. So is there any way around this at all? Basically all I want to do is detect when the mouse is no longer within the body of the document. But I don't want to go adding code to every element in the document unless absolutely necessary
 
You could put a big div over the whole page, absolutely positioned and invisible, and then do the onmouseout on that, or so it would seem.

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Nevermind that idea.

You could play around with this:
Code:
function doIt(e)
{
if (!e) e=window.event;
winHeight = (document.documentElement) ? document.documentElement.clientHeight : document.body.clientHeight;
if(e.pageY<=1 || e.pageY>(winHeight-2)) {alert('come back');}
else {return false;}
}
calling it like [tt]onMouseMove="doIt(event)"[/tt]

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top