This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes HTML, CSS and JavaScript and the fly likes How can I capture MOUSE MOVE and call a function? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "How can I capture MOUSE MOVE and call a function?" Watch "How can I capture MOUSE MOVE and call a function?" New topic
Author

How can I capture MOUSE MOVE and call a function?

Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
For example, if my mouse is moved on screen, a function will be called, if it stop, nothing will be done. I've a simple script as follows:
<heaD>
<script>
function Key_Up(e) {
alert("message");
}
document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = Key_Up;
</script>
</head>
<body>1</body>

However, it doesn't do what i suppose i want to do, if my mouse move, the alert message will LOOP forever, but my basic idea is when my mouse move, alert appear, press OK using keyboard, alert message disappear (<---but now the alert appear again). Please would anyone suggest a solution?Thanks


Thanks everyone who helped me
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
Forget to say that my script aims on running at Netscape 4.xx, not works for IE
Yuriy Fuksenko
Ranch Hand

Joined: Feb 02, 2001
Posts: 413
You should have a flag on yout page - if mouse move, and flag is set, than show dialog( alert).
If user hit OK on alert - reset a flag, so alert will not appear.
You might need to replace standart alert function with some thing else - either layer or another browser window (by the way, showModalDialog from for IE is exactly what you need).
By the way, for IE you need not to call captureEvent function, so put
if (!document.all) window.captureEvent(...)
 
 
subject: How can I capture MOUSE MOVE and call a function?