这个iframe有点奇怪

今天为了做了一个可以自动适应高度的iframe,

<iframe src="Balance.aspx" onload="javascript:resize_iframe();" scrolling="no" name="userinfo" height="0" width="0" frameborder="0">
</iframe>

用下面的js控制:

alert(userinfo.document.body.scrollHeight);
alert(userinfo.document.body.scrollWidth);

document.all(
"userinfo").height = userinfo.document.body.scrollHeight; 
document.all(
"userinfo").width = userinfo.document.body.scrollWidth;


这么控制还是不行,iframe的高度和宽度就是不变,总是0  简直把人搞疯掉了..

后来,偶尔把width="0",改成了width="1",奇迹出现了! js脚本可以控制了!!

接着的测试发现,只要把width="0",那么,userinfo.document.body.scrollHeight 获取到的高度值总是0。但是,奇怪的是,把height="0",是没有影响的!

不知道这是不是iframe的一个bug.
原文地址:https://www.cnblogs.com/silva/p/289084.html