»
EnglishFrenchVietnamese

Print - Detecting Mouse Position - JavaScriptBank.com

Full version: jsB@nk » Pointer » Detecting Mouse Position
URL: http://www.javascriptbank.com/detecting-mouse-position.html

Detecting Mouse Position © JavaScriptBank.comThis is an easy way to determine the mouse position on a Web page. Click anywhere on the page and the coordinates will be displayed.

Full version: jsB@nk » Pointer » Detecting Mouse Position
URL: http://www.javascriptbank.com/detecting-mouse-position.html



JavaScript
<script type="text/javascript">// Created by: Roy Marchand | http://www.expertsrt.comfunction showit() {  document.forms['theform'].xcoord.value=event.x;  document.getElementById('spanx').innerHTML='x = '+event.x;  document.forms.theform.ycoord.value=event.y;  document.getElementById('spany').innerHTML='y = '+event.y;}function showitMOZ(e) {  document.forms['theform'].xcoord.value=e.pageX;  document.getElementById('spanx').innerHTML='x = '+e.pageX;  document.getElementById('spany').innerHTML='y = '+e.pageY;  document.forms.theform.ycoord.value=e.pageY;}if (!document.all) {  window.captureEvents(Event.CLICK);  window.onclick=showitMOZ;} else {  document.onclick=showit;}</script><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->


HTML
<h4>You can store them in form fields</h4><form name="theform">x = <input name="xcoord" type="text" readonly size="5"> y = <input name="ycoord" type="text" readonly size="5"></form><p><h4>or as plain text</h4><span id="spanx"> </span> <span id="spany"> </span><!--    This script downloaded from www.JavaScriptBank.com    Come to view and download over 2000+ free javascript at www.JavaScriptBank.com-->