function iFrameHeight() {
var ifm= document.getElementById("framedetail");
var subWeb = document.frames ? document.frames["framedetail"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
}
希望能帮到你。 ######ifm.contentDocument 报null######
function reSizeParentIframe() { var realHeight = 0; if(navigator.userAgent.search(/Trident/i)>0){ realHeight = window.document.documentElement.offsetHeight+35; }else if (navigator.userAgent.indexOf("Firefox") > 0 || navigator.userAgent.indexOf("Mozilla") > 0 || navigator.userAgent.indexOf("Safari") > 0 || navigator.userAgent.indexOf("Chrome") > 0) { // Mozilla, Safari,Chrome, ...
realHeight = window.document.documentElement.offsetHeight-7; } else if (navigator.userAgent.indexOf("MSIE") > 0) { // IE
var bodyScrollHeight = window.document.body.scrollHeight + 21; //取得body的scrollHeight
var elementScrollHeight = window.document.documentElement.scrollHeight + 1; //取得documentElement的scrollHeight
realHeight = Math.max(bodyScrollHeight, elementScrollHeight); //取当中比较大的一个
} else {//其他浏览器
realHeight = window.document.body.scrollHeight + window.document.body.clientHeight + 1; } var uheight = $("#uapmhead", window.parent.document).height(); var cheight = window.parent.document.documentElement.clientHeight-uheight-5; if (realHeight < cheight) { realHeight = cheight; } if ($("iframe[src='views/businessview/bizAnalyview/businessCount.jsp']", window.parent.document).is("iframe")) { $("iframe[src='views/businessview/bizAnalyview/businessCount.jsp']", window.parent.document).height(realHeight); } }
###### 首先,感觉上面两位的回答。我用下面这个方法解决了: function setIframeHeight(iframe) { if (iframe) { var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow; if (iframeWin.document.body) { iframe.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight; } } };
window.onload = function () { setIframeHeight(document.getElementById('frame0')); }; ###### http://jsbin.com/qutovo/7/edit?html,css,output . 是这种效果哦吗?不用一句js