This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes X and Y coordinates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "X and Y coordinates" Watch "X and Y coordinates" New topic

X and Y coordinates

Kodo Tan
Ranch Hand

Joined: Aug 14, 2001
Posts: 105
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 ?
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4351

not offhand but here is where i would look

Visit my download page
A1ien51 CNEUFOs

Joined: Nov 05, 2001
Posts: 16
Here is the code, I put the output into text boxes;

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
<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>
I agree. Here's the link:
subject: X and Y coordinates
It's not a secret anymore!