Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mouse cursor position in Javascript?

Tags:

javascript

How do I get cursor X and Y in javascript?

var $curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var $curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;

I had found this two, but they appear as "undefined". Any ideas?

Thanks!

like image 701
Roger Travis Avatar asked Jul 14 '10 17:07

Roger Travis


1 Answers

I assume you don't want a framework answer. If not, try this:

document.onclick=function(evt) {
    evt = (evt || event);
    alert(evt.clientX + ' ' + evt.clientY);
}

I wasn't sure what event you wanted, so I just used an onclick event.

like image 50
RightSaidFred Avatar answered Sep 30 '22 06:09

RightSaidFred