Wednesday, December 21, 2005

Javascript document.onmouseover

document.onmouseover=GetCoordinates;
function GetCoordinates(e){
if (navigator.appName=="Netscape") {
xVal = parseInt(e.pageX);
yVal = parseInt(e.pageY);
}
if (navigator.appName.indexOf("Microsoft")!=-1) {
xVal=parseInt(event.x);
yVal=parseInt(event.y);
}
}


This line of code document.onmouseover=GetCoordinates; causes the onmouseover to be fired and calls function GetCoordinates, which is used to keep track of every single mouse movement. Also, the appName property of the javascript navigator object is used to identify the user's browser. If the browser is Netscape, e.pageX and e.pageY return the (X,Y) coordinates of the mouse pointer. Otherwise, event.x and event.y are used to return the (X,Y) coordinates of the mouse pointer in IE.

No comments: