经典代码 iFrame 自适应高度,在IE6/IE7/IE8/Firefox/Opera/Chrome/Safari通过测试。
var ifm= document.getElementById("user_iframe");
var subWeb = document.frames ? document.frames["user_iframe"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
两个iframe嵌套的
var ifm= document.getElementById("user_iframe");
var subWeb = document.frames ? document.frames["user_iframe"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
//得到父iframe
var ifmParent= window.parent.document.getElementById("main_iframe");
var subWebParent = window.parent.document.frames ? window.parent.document.frames["main_iframe"].document : ifmParent.contentDocument;
if(ifmParent != null && subWebParent != null){
ifmParent.height = subWeb.body.scrollHeight;
}