JavaScript Code

JavaScript – Get Mouse Position

This little function will retrieve the X & Y (horizontal & vertical) position of the mouse cursor in Internet Explorer, FireFox, and all other browsers.

function moveObject( e ) {
var tempX = 0;
var tempY = 0;
if (document.all) {
// must be IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
} else {
tempX = e.pageX;
tempY = e.pageY;
}
// prevent any negative values
if (tempX < 0){tempX = 0} if (tempY < 0){tempY = 0} alert("X:" + tempX + "\r\nY:" + tempY); } [/code]

Share

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image