<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!

解决方案 »

  1.   


        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);
        }
      

  2.   

    试了下  .ownerDocument是每个浏览器都支持的属性,但并不等于contentWindow,
    比如:我要改变iframe里的css就无效:(上面的h的值也并不是一个对象的)
    _iframe.ownerDocument.getElementById('haha').style.color='#f00';顺便问下,你是怎么跟踪的!
      

  3.   

    (iframe.contentWindow || iframe).document
      

  4.   

    LZ,对不起.我搞错了不用那样的如果你的代码没错,你用IIS查看,不要直接在浏览器中找打开页面就可以的!
      

  5.   

    5楼的肯定不行,  难道是我浏览器的问题? 我的版本  Chrome 9.0.597.98
      

  6.   

    安全问题,你用http://这种格式来访问就可以了。
      

  7.   


    哦,终于懂了!其实6楼早就回答了,只是我没领悟到!
    结论是: Chrome会把本地iframe 也当成是跨域,会报错!用http://就可以了  thanks!
      

  8.   


    哦,终于懂了!其实6楼早就回答了,只是我没领悟到!
    结论是: Chrome会把本地iframe 也当成是跨域,会报错!用http://就可以了  thanks!请问怎么用http://