Bruce Lee wrote:
Martin
I've put up a test case at
http://www.mycgiserver.com/~directcareer/js/test.html
I need IE6 to correctly recognise the coordinates like Firefox does,
I've tried different methods but no luck so far. Any help would be greatly
appreciated - I've spent far too much time on this!
Apparently a bit of a 'race condition' there...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
</head>
<body>
<table height=20><tr><td></td></tr></table>
<table width=500 height=100 border=1>
<tr>
<td width=100 bgcolor=blue>
</td>
<td bgcolor=yellow>
<table width=100% id="tab" width=50 height=20 border=1 bgcolor=red>
<tr>
<td>
<script type="text/javascript">
function getAbsX(elt) { return (elt.x) ? elt.x : getAbsPos(elt,"Left");
}
function getAbsY(elt) { return (elt.y) ? elt.y : getAbsPos(elt,"Top");
}
function getAbsPos(elt,which) {
iPos = 0;
while (elt != null) {
iPos += elt["offset" + which];
elt = elt.offsetParent;
}
return iPos;
}
onload=function()
{
alert(
'This red table (id:tab) is at - X:'+
getAbsX(document.getElementById("tab"))+
',Y:'+getAbsY(document.getElementById("tab"))
);
}
</script>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Don't forget doctypes for testing like this; layout will vary with
different ones specified.