Page 1 of 1
Get mouse coordinates
Posted: Mon Oct 03, 2005 4:32 am
by pilau
How do I get the mouse coords?
I tried "window.event.clientX" and "window.event.clientY" - itworks on IE6 but it won't work on FireFox.
Posted: Tue Oct 04, 2005 12:09 pm
by anjanesh
Not tested but something like this has a workaround.
Code: Select all
function foo(e)
{
if (window.Event)
{
x = e.screenX;
y = e.screenY;
}
else
{
x = window.event.clientX;
y = window.event.clientY;
}
}
Posted: Tue Oct 04, 2005 12:14 pm
by feyd
should probably do a typeof test to see if the object exists or not..
Posted: Tue Oct 04, 2005 1:07 pm
by pilau
Bah.. didn't work on FF.
Well drop it I'm changing the design and layouy anyway. Thanks.
Posted: Tue Oct 04, 2005 1:42 pm
by anjanesh
This works in both IE 6.0 and FF 1.0.7
Code: Select all
<html>
<head>
<script type="text/javascript">
function foo1(scrObj, e)
{
e = e || window.event;
var id1 = document.getElementById("id1");
var x = e.screenX || e.clientX;
var y = e.screenY || e.clientY;
id1.innerHTML = x + ", " + y;
}
</script>
</head>
<body>
<div id="id1" style="border:1px solid black;width:250px;height:250px" onmousemove="foo1(this, event)">
Test Contents
</div>
</body>
</html>
Posted: Tue Oct 04, 2005 5:40 pm
by pilau
anjanesh wrote:This works in both IE 6.0 and FF 1.0.7
I promise I'll check it out
