Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

X and Y coordinates

 
Kodo Tan
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
Anyone knows the HTML syntax for capturing the X and Y coordinates of the mouse that is compatible to both Netscape and IE browsers ?
Regards.
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not offhand but here is where i would look http://www.w3.org/TR/REC-html32.html
or http://www.w3schools.com/html/html_reference.asp
 
A1ien51 CNEUFOs
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code, I put the output into text boxes;

<html>
<head>
<script>
var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var Xtemp = 0;
var Ytemp = 0;
function getMouseXY(e) {
if (IE) {
Xtemp = event.clientX + document.body.scrollLeft;
Ytemp = event.clientY + document.body.scrollTop;
}
else {
Xtemp = e.pageX;
Ytemp = e.pageY;
}
if (Xtemp < 0){Xtemp = 0;}
if (Ytemp < 0){Ytemp = 0;}
document.ShowLoc.XMousePos.value = Xtemp;
document.ShowLoc.YMousePos.value = Ytemp;
return true
}
</script>
</body>
</head>
<body>
<form name="ShowLoc">
X Position:<input type="text" name="XMousePos" value="0" size="5"><br>
Y Position:<input type="text" name="YMousePos" value="0" size="5"><br>
</form>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic