Click to See Complete Forum and Search --> : onmouseOut does not fire after returning from ALT+TAB
spieh
04-12-2007, 03:41 PM
I made a DTHML menu using CSS and Javascript. Here is something I noticed that I didn't find anything about searching the forums.
I mouseover the menu and the submenu appears and I move my mouse onto the submenu. Then I ALT+TAB to any other app or window and move the mouse to a position such that when I ALT+TAB back to the window containing the menu the mouse will no longer be anywhere inside of the object that fired the mouseover event.
When I do this, the mouseout event attached to the submenu never fires and the submenu remains visible.
Any ideas?
mrhoo
04-12-2007, 05:52 PM
alt-tab moves the focus, not the mouse. Use focus and blur for key events
simulating mouseover and mouseout.
konithomimo
04-12-2007, 10:24 PM
The onmouseout function can only fire when the mouse moves away from the object while the window is being actively used. When you alt+tab away and then come back the window will not have registed the onmouseout, since it did not happen while the window was active. The onmouseout will not fire until the next time you mouseover and then mouseout of that object. Even using onblur wont fix this problem. Instead you will have to check and see if the mouse is not over the menu when it moves, and if not then hide the menu. Most likely you would do this from the body element.
spieh
04-13-2007, 09:40 AM
Is there someway to set a timeout to hide the menu and cancel the timeout when you are currently on the menu?
spieh
04-15-2007, 04:33 AM
I did this.
window.onblur = hideall;
function hideall ()
{
divArray = document.getElementsByTagName('div');
for (var i = 0;i<divArray.length;i++)
{
if(divArray[i].className == "visibleMenu")
{
divArray[i].className == "hiddenMenu";
}
}
}
This will hide every menu in my page if the window loses focus. However it seems like it could be resource intensive checking every div every time the window loses focus. It works but maybe not the best way of doing it.
The question really is, why would the user alt+tab while a menu is open. It's pretty unlikely unless the user had an immediate need to swap processes. In that case I think it's completely acceptable to leave the menus "open" when the window blurs.
btw, if you were to use something like the suckerfish menu (which relies on CSS and not JS) then the problem you have wouldn't arise.
http://alistapart.com/articles/dropdowns
spieh
04-16-2007, 04:16 PM
When an anchor link gains focus window.onblur executes and hides all the menus. This doesn't really matter if the link goes somewhere but if I have href="#" then I would like the menu to remain visible if the clicked link doesn't go anywhere. This only happens once in IE but it fires window.onblur multiple times in firefox when the links gain focus.
Guess I'll have to come up with some other way to fix the issue.
BTW, I know its unlikely for an average user to alt-tab while moving over a menu. The place this is being deployed uses a soft phone system that has a small pop-up that steals focus when a call comes into the phone. So the user may not alt-tab but this issue is for when the window loses focus for any reason while the menu is active.