This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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: 4363
2
Java
  • 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>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic