日期:2014-05-16  浏览次数:20371 次

获取iframe窗口的 contentWindow 不兼容Chrome ?

<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

引用:
JScript code

    function show(){
        var _iframe = document.getElementById('aa');
        //在Chrome内跟踪_iframe.contentWindow得到的是object;但这个object是个空对象;
        //所以跟踪了一下,发现在Chrome里,_iframe下有一个子对……

------解决方案--------------------
(iframe.contentWindow 
------解决方案--------------------
 iframe).document
------解决方案--------------------
LZ,对不起.我搞错了。。。不用那样的

如果你的代码没错,你用IIS查看,不要直接在浏览器中找打开页面就可以的!
------解决方案--------------------
安全问题,你用http://这种格式来访问就可以了。