November 16, 2000 - Computing the Mouse Click Location
November 16, 2000 Computing the Mouse Click Location Tips: November 2000
Yehuda Shiran, Ph.D.
|
event
object. In Internet Explorer, the x and y coordinates of the mouse are defined
by the clientX
and clientY
properties, respectively. In Netscape Navigator, they are defined by pageX
and pageY
,
respectively. This tip is set up to print, upon clicking, the location of the
mouse. Try clicking in this window and you'll see the exact coordinates pop up.
The event handler of this click is as follows:
function printEvent(e) {
if (navigator.appName == "Microsoft Internet Explorer"){
mX = event.clientX;
mY = event.clientY;
}
else {
mX = e.pageX;
mY = e.pageY;
}
alert("Click at x = " + mX + " and y = " + mY);
}