Yesterday while working on a script and I wanted to know the cursor X, Y coordinates. Suprisingly I forgot how to get the X and Y coordinates of mouse. After thinking for some time, its strike that everything related to the current state is stored in events. So How to get the X and Y positions.
-capture mousemove event and list down all its properites
This is how I find X and Y coordinates
<title>Get Mouse Coordinates</title>
* capture mousemove event, this statement will cause browser to
* call getMouseCoordites function each time mouse moves
*identify which event is supported
* Based on that collect pageX and pageY properties of the event object
* pageX and pageY gets the X and Y cursor coordinates
ev = event || window.event;
divObj.innerHTML = “Mouse X:”+ev.pageX + ” Mouse Y:”+ev.pageY;
//assign the mouseCoord Object to divObj
divObj = document.getElementById(“mouseCoord”);
<div id=”mouseCoord”>Mouse Coordinates position will be displayed here.
Script works well with Mozilla, For IE need to do further modification in finding the exact position by calculating different properties value.