Monday, August 20, 2012

Simple HTML/Javascript Codes to Display your Live Mouse Coordinates

Here they are:


<html>
<head>

<script type="text/javascript">

function showXY()
{
   var s = 'X=' + window.event.clientX + ' Y=' + window.event.clientY;
   document.getElementById('coordinates').innerText = s;
}

</script>
</head>

<body onmousemove=showXY()>

<div id="coordinates"></div>

</body>
</html>


The key component for this to work is highlighted in green. However this won't work in Firefox. The firefox friendly version can be found here. Sorry I wasn't aware of the Firefox problem earlier. Another way to fix this is to use JQuery.

No comments:

Post a Comment