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

Q1152 How can I get the x and y coordinate of the mouse pointer within the document?

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

Q1152 How can I get the x and y coordinate of the mouse pointer within the document?

The following works in Netscape Navigator 4+ and Internet Explorer 4+:

<html>
<head>
<script language="JavaScript">
if (document.layers) {
    window.captureEvents(Event.MOUSEMOVE);
    window.onmousemove=move;
}
else if (document.all)
   document.onmousemove=move;

function move(e) {
    if (document.all)
        document.myForm.x.value=window.event.clientX, document.myForm.y.value=window.event.clientY;
    else if (document.layers)
        document.myForm.x.value=e.pageX, document.myForm.y.value=e.pageY;
}
//--></script>
</head>

<body>

<form name="myForm">
<input type="text" name="x">
<input type="text" name="y">
</form>

</body>
</html>

Feedback on 'Q1152 How can I get the x and y coordinate of the mouse pointer within the document?'


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.