2Apr/080

Javascript: Find X og Y koordinater fra musen

Få vist koordinaterne fra musens placering på skærmen via Javascript.

Javascript

<script type="text/javascript">
function getMousePos(myEvent) { 

  //NS
  if (document.layers||document.getElementById&&!document.all) {
  document.getElementById("myX").innerHTML = myEvent.pageX;
  document.getElementById("myY").innerHTML = myEvent.pageY; 
  }

  //IE
  else if (document.all) {
  document.getElementById("myX").innerHTML = window.event.clientY;
  document.getElementById("myY").innerHTML = window.event.clientY;
  }

}
document.onmousemove = getMousePos;
</script>

html

<b>Page X koordinater:</b>
<span id="myX">0</span><br>

<b>Page Y koordinater:</b>
<span id="myY">0</span>

Related Posts:

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment

No trackbacks yet.