<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>
3.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);
}
比如:我要改变iframe里的css就无效:(上面的h的值也并不是一个对象的)
_iframe.ownerDocument.getElementById('haha').style.color='#f00';顺便问下,你是怎么跟踪的!
哦,终于懂了!其实6楼早就回答了,只是我没领悟到!
结论是: Chrome会把本地iframe 也当成是跨域,会报错!用http://就可以了 thanks!
哦,终于懂了!其实6楼早就回答了,只是我没领悟到!
结论是: Chrome会把本地iframe 也当成是跨域,会报错!用http://就可以了 thanks!请问怎么用http://