spacer
Yehuda Shiran November 16, 2000
Computing the Mouse Click Location
Tips: November 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Some applications require an exact positioning of the mouse in order to work properly. These mouse coordinates can be found using the 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);
}

People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business