Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q1374 When capturing an event, is there any way to find out the mouse position relative to the page?

irt.org | Knowledge Base | JavaScript | Event | Q1374 [ previous next ]

Q1374 When capturing an event, is there any way to find out the mouse position relative to the page?

Use pageX and pageY in Netscape navigator 4, and clientX and clientY in Internet Explorer 4+:

<script language="JavaScript"><!--
function coords(e) {
    if (document.layers) {
        alert(e.pageX + ',' + e.pageY);
    }
    else if (window.event) {
        alert(window.event.clientX + ',' + window.event.clientY);
    }
}
//--></script>

<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>

<form>
<input type="button" value="Click me!" onClick="coords(event)">
</form>

<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br>

Feedback on 'Q1374 When capturing an event, is there any way to find out the mouse position relative to the page?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 6th July 2009. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2009 irt.org, All Rights Reserved.