screenXEvent Property
Event Object
Definition and Usage
The screenX event property returns the horizontal coordinate of the mouse pointer relative to the screen when the event occurred.
Syntax
event.screenX
Example
Example
The following example shows the coordinates of the mouse pointer when the event occurs:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script type="text/javascript">
function coordinates(event){
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
Click somewhere in the document. A message box will show the x and y coordinates of the pointer relative to the screen.
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script type="text/javascript">
function coordinates(event){
x=event.screenX
y=event.screenY
alert("X=" + x + " Y=" + y)
}
</script>
</head>
<body onmousedown="coordinates(event)">
<p>
Click somewhere in the document. A message box will show the x and y coordinates of the pointer relative to the screen.
</p>
</body>
</html>
Try it Yourself »
Event Object Other Extensions