Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q232 Is it possible to trap the mouse moving?

irt.org | Knowledge Base | JavaScript | Pointer | Q232 [ previous next ]

Q232 Is it possible to trap the mouse moving?

In Netscape Navigator 4 and Internet Explorer 4 you can use the following code:

<HTML>
<HEAD>

<SCRIPT LANGUAGE="JavaScript"><!--
if (navigator.appName == 'Netscape') {
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = netscapeMouseMove;
}

function netscapeMouseMove(e) {
    if (e.screenX != document.test.x.value || e.screenY != document.test.y.value) {
        document.test.x.value = e.screenX;
        document.test.y.value = e.screenY;
    } 
}

function microsoftMouseMove() {
    if (window.event.x != document.test.x.value || window.event.y != document.test.y.value) {
        document.test.x.value = window.event.x;
        document.test.y.value = window.event.y;
    }
}
//--></SCRIPT>

</HEAD>

<BODY onMousemove="microsoftMouseMove()">

<FORM NAME="test">
X: <INPUT TYPE="TEXT" NAME="x" SIZE="4"> Y: <INPUT TYPE="TEXT" NAME="y" SIZE="4">
</FORM>

</BODY>
</HTML>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.