操纵页面中iframe里的对象
父页面:
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<html>
<head>
<title></title>
<script type="text/javascript">
function scrollIframe()
{document.getElementById("ifrm").contentWindow.document.body.scrollTop = 100
alert(document.getElementById("ifrm").contentWindow.document.body.scrollTop)
}
</script>
</head>
<body onload="document.body.scrollTop = 100;">
<div style="height:500px">
<input type = "button" value="设置iframe的scrollTop为100px" onclick = scrollIframe()><br>
<iframe id=ifrm src="aaa.html" width=500px height=100px; /><br>
</div>
</body>
</html>
操纵了一个contentWindow对象。
子页面 aaa.html :
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
<html>
<head>
</head>
<script type="text/javascript">
function getScrollTop()
{
alert(document.body.scrollTop+"px");
}
</script>
<body>
<div style="height:800px">
<br>
<br>
<br>
<div style="text-align:right"><input id=btn type = "button" value="获取iframe中的scrollTop" onclick="getScrollTop
()"><div>
<div style="position:absolute;width:100px;height:50px;z-index:1000;left:350px">
adsfsdfsdfsd
</div>
</div>
</body>
</html>