画面がスクロールされた場合の座標値を考慮した絶対座標を取得するにはこちらの記事を参照してください。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
<!--
.frame {
height:120px;
border:1px solid #0094ff;
}
-->
</style>
<script type="text/javascript">
function onButtonClick() {
var textbox = document.getElementById('TextArea1');
var elem = document.getElementById('frame1');
var rect = elem.getBoundingClientRect();
textbox.value = 'top:' + rect.top+'\r\n';
textbox.value += 'left:' + rect.left+'\r\n';
textbox.value += 'bottom:' + rect.bottom+'\r\n';
textbox.value += 'right:' + rect.right+'\r\n';
}
</script>
</head>
<body>
<div>Position Demo</div>
<div><textarea id="TextArea1" rows="16" cols="80"></textarea></div>
<div><input id="Button1" type="button" value="button" onclick="onButtonClick();" /></div>
<div id="frame1" class="frame">frame1</div>
<div id="frame2" class="frame">frame2</div>
<div id="frame3" class="frame">frame3</div>
<div id="frame4" class="frame">frame4</div>
<div id="frame5" class="frame">frame5</div>
</body>
</html>
var textbox = document.getElementById('TextArea1');
var elem = document.getElementById('frame1');
var rect = elem.getBoundingClientRect();
textbox.value = 'top:' + rect.top+'\r\n';
textbox.value += 'left:' + rect.left+'\r\n';
textbox.value += 'bottom:' + rect.bottom+'\r\n';
textbox.value += 'right:' + rect.right+'\r\n';
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style>
<!--
#outerframe{
border: 1px solid #ad1a1a;
margin-top:16px;
margin-left:16px;
padding-top:32px;
padding-left:16px;
}
.frame {
height:120px;
border:1px solid #0094ff;
}
-->
</style>
<script type="text/javascript">
function onButtonClick() {
var textbox = document.getElementById('TextArea1');
var elem = document.getElementById('frame1');
var rect = elem.getBoundingClientRect();
var elemtop = rect.top + window.pageYOffset;
var elemleft = rect.left + window.pageXOffset;
var elembottom = rect.bottom + window.pageYOffset;
var elemright = rect.right + window.pageXOffset;
textbox.value = 'top:' + elemtop+'\r\n';
textbox.value += 'left:' + elemleft+'\r\n';
textbox.value += 'bottom:' + elembottom+'\r\n';
textbox.value += 'right:' + elemright+'\r\n';
}
</script>
</head>
<body>
<div>Position Demo</div>
<div><textarea id="TextArea1" rows="16" cols="80"></textarea></div>
<div><input id="Button1" type="button" value="button" onclick="onButtonClick();" /></div>
<div id="outerframe">
<div id="frame1" class="frame">frame1</div>
<div id="frame2" class="frame">frame2</div>
<div id="frame3" class="frame">frame3</div>
<div id="frame4" class="frame">frame4</div>
<div id="frame5" class="frame">frame5</div>
</div>
</body>
</html>