87,922
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
function show(){
var iframe=document.getElementById('aa');
var h=iframe.contentWindow.document.body.offsetHeight;
alert(h)
}
</script>
</head>
<body>
<iframe id="aa" src="3.html" frameborder="0" scrolling="no" width="100%" height="200" ></iframe>
<input type="button" value="click" onclick="show()"/>
</body>
</html>
<body>
test
</body>
为什么Chrome浏览器弹不出 3.html的高度呢? thank everyone!
function show(){
var _iframe = document.getElementById('aa');
//在Chrome内跟踪_iframe.contentWindow得到的是object;但这个object是个空对象;
//所以跟踪了一下,发现在Chrome里,_iframe下有一个子对象ownerDocument,相当于FF,IE等浏览器的_iframe.contentWindow.document
var h = _iframe.contentWindow.document? _iframe.contentWindow.document.body : _iframe.ownerDocument.body;
alert(h.offsetHeight);
}