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

Q1260 Is there a way to know the coordinates on the page where the mouse was clicked?

irt.org | Knowledge Base | DHTML | Q1260 [ previous next ]

Q1260 Is there a way to know the coordinates on the page where the mouse was clicked?

In version 4 browsers and upwards:

<script type="text/javascript" language="JavaScript"><!--
function clicked(e) {
    var x=y=0;

    if (document.layers) {
        x = e.pageX;
        y = e.pageY;
    }
    else if (document.all) {
        x = window.event.x;
        y = window.event.y;
    }

    alert('x = ' + x + ',  y = ' + y);
}
//--></script>

<table width="100%" height="100%">
<tr>
<td valign="top">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
<td valign="top" align="center">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
<td valign="top" align="right">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
</tr>
<tr>
<td valign="middle">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
<td valign="middle" align="center">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
<td valign="middle" align="right">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
</tr>
<tr>
<td valign="bottom">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
<td valign="bottom" align="center">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
<td valign="bottom" align="right">
<a href="#" onClick="if (window.event || document.layers) clicked(event)">click me</a>
</td>
</tr>
</table>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.