In this case, I have a layer of a specific height and width, and a function that detects when and where the mouse is clicked on the document. If the position of the pointer when the mouse is clicked is within the layer, an alert box shows up with an appropriate message; if the pointer is outside the layer, a different message appears.
Now, if you tried this example in Internet Explorer, you probably got hit with a couple of error messages. This is because Internet Explorer doesn't support "layerX" or "layerY", preferring instead to use the "x" and "y" properties. Take a look at this rewrite of the previous example, which demonstrates:
document.onmousedown = CoordCheck;
// uncomment the next two lines to see coordinate data
// alert ("The x-coordinate is " + event.x);
// alert ("The y-oordinate is " + event.y);
if((event.x < 10 || event.y < 10) || event.x > 420 || event.y >
<div style="background-color:cyan; position:absolute; top:10; left:10;
width:410; height:50"> Try clicking the mouse outside this layer. Then
try clicking inside. </div>
In addition to these properties, there's also the "screenX" and "screenY" properties, which return the horizontal and vertical position of the cursor relative to the screen. Netscape additionally exposes the "pageX" and "pageY" properties, which returns the horizontal and vertical position of the cursor relative to the page.