<html>
<script language="javascript">
function findPosX(obj) {
var curleft = 0;
if (obj.offsetParent) { // , offsetParent body
while (obj.offsetParent) {//
curleft += obj.offsetLeft;//
obj = obj.offsetParent;
}
} else if (obj.x) curleft += obj.x;
return curleft;
}
function findPosY(obj) {
var curtop = 0;
if (obj.offsetParent) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
} else if (obj.y) curtop += obj.y;
return curtop;
}
function getPos(){
return {x:findPosX(document.getElementById("p36table")),y:findPosY(document.getElementById("p36table"))};
}
function showPos(){
var pos = getPos();
alert("x=="+pos.x+"y=="+pos.y);
}
</script>
<div id="parentdiv" style="position:relative; border:5px solid;" >
<table id="p36table" style="position: relative; " width="185" border="1" align="center" cellpadding="0" cellspacing="0">
<tr>
<td>
<iframe frameborder=0 scrolling=no width="185" height="170" marginHeight=0 marginWidth=0 align="left"
src='#'></iframe>
</td>
<td onClick="javascript:showPos();"> </td>
</tr>
</table>
</div>
</html>
:
1:
function getAbsPoint(e)
{
var x = e.offsetLeft, y = e.offsetTop;
while(e=e.offsetParent)
{
x += e.offsetLeft;
y += e.offsetTop;
}
alert("x:"+x+","+"y:"+y);
}
2:
function getAbsPoint(obj)
{
var x,y;
oRect = obj.getBoundingClientRect();
x=oRect.left
y=oRect.top
alert("("+x+","+y+")")
}
JS
1。 :
screen.width
screen.height
2。 :
document.body.clientWidth
document.body.clientHeight
3。 ( Border、Scroll )
document.body.offsetWidth
document.body.offsetHeight