Hello, I grabbed this function below from a webpage that returns sets the X,Y coordinates to a variable. It works perfect in Firefox but not in IE - I should say it works in IE too, but not how I want it to.
In IE it returns the X,Y coordinates from your current viewing point on the page, meaning if you are scrolled halfway down the page and your cursor was top left of the screen it would return 0,0. When it should return 0,>0.
How do I fix this function to return the correct X,Y coordinates of the cursor regardless of your viewing point of the screen in IE?
In IE it returns the X,Y coordinates from your current viewing point on the page, meaning if you are scrolled halfway down the page and your cursor was top left of the screen it would return 0,0. When it should return 0,>0.
How do I fix this function to return the correct X,Y coordinates of the cursor regardless of your viewing point of the screen in IE?
Code:
var tempX = 0;
var tempY = 0;
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
function getMouseXY(e) {
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + document.body.scrollLeft;
tempY = event.clientY + document.body.scrollTop;
}
else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
if (tempX < 0){tempX = 0;}
if (tempY < 0){tempY = 0;}
return true;
}