因为ie7之前的版本不兼容contentDocument属性(使用的是HTMLIFrameElement.contentWindow.document),所以不能使用obj.contentDocument.body.scrollHeight属性设置iframe的高度
在网上找了一些解决方法试了下,最后选择了一种最简单的
function iFrameHeight(obj) {
var subWeb = document.frames ? document.frames["frm"].document :obj.contentDocument;
if(obj != null && subWeb != null) {
obj.height = subWeb.body.scrollHeight;
}
}
“frm”为iframe的id,iframe的onload事件调用iFrameHeight(this)。
(有人说用谷歌浏览器不能正常显示,我自己用最新版试了下,发现可以正常显示,不知道他们说的是什么版本的)