You can store them in form fields
or as plain text |
Add this to a file called mousePosition.js:
/* JavaScripts.com http://javascripts.com
Created by: Roy Marchand | http://www.expertsrt.com */
function 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;
}
Add this to the <head> portion if your page: <script type="text/javascript" src="mousePosition.js"></script> Add this in the <body> where you want the fields to appear: <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>Good Luck! |