Get Current Mouse Position Using Java Script

by satheeshkumar 2013-08-08 15:22:34

Get Current Mouse Position Using Java Script ,

To get the current mouse pointer use the following script function,



<script type="text/javascript">
window.onload = init;
function init() {
if (window.Event) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getCursorXY;
}

function getCursorXY(e) {
document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}
</script>

<input type="text" id="cursorX" size="3"> X-position
<br /><br />
<input type="text" id="cursorY" size="3"> Y-position
1067
like
0
dislike
0
mail
flag

You must LOGIN to add comments