Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

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

You are here: irt.org | FAQ | DHTML | Q1260 [ previous next ]

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>

©2018 Martin Webb