Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | JavaScript | Pointer | Q1152 [ previous next ]

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?'

©2018 Martin Webb