|
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?'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.