I want to get current X and Y position of the cursor in the browser when I click or focus on some of the html elements. When I do this with onclick
it worked. But with onfocus
it didn't. Please see the examples below..
Working code
<html>
<head>
<title>Untitled</title>
<script type="text/javascript">
<!--
function findXCoord(evt) {
if (evt.x) return evt.x;
if (evt.pageX) return evt.pageX;
}
function findYCoord(evt) {
if (evt.y) return evt.y;
if (evt.pageY) return evt.pageY;
}
//-->
</script>
</head>
<body>
<a onclick="alert('The x coordinate is: ' + findXCoord(event) + ' and the y coordinate is: ' + findYCoord(event));">Hi</a>
</body>
But when I change onclick to onfocus, It didn't show the x,y positions
(onclick="alert.... to onfocus="alert.......)