//第一个iframe
<iframe style="overflow: auto;" id="myframe" name="myframe" frameborder="0" scrolling="no" width="100%" onload="setIframeHeight(this)">
//第一个iframe的方法,目的自动跳转iframe的高度
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('external-frame'));
};
//第二个iframe
<iframe id="tab1If" scrolling="no" style="overflow:auto;min-
height:450px;width:100%;border:none;" src="/home.jsp" >
//子页面重新修改父页面iframe高度
function reSizeParentIframe() {
var realHeight = 0;
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 + 35;
} else if (navigator.userAgent.indexOf("MSIE") > 0) { // IE
var bodyScrollHeight = window.document.body.scrollHeight + 21;
var elementScrollHeight = window.document.documentElement.scrollHeight + 1;
realHeight = Math.max(bodyScrollHeight, elementScrollHeight);
} else {//其他浏览器
realHeight = window.document.body.scrollHeight +
window.document.body.clientHeight + 1;
}
if (realHeight < 450) {
realHeight = 450;
}
if ($("#myframe", window.parent.document).is("iframe")) {
$("#myframe", window.parent.document).height(realHeight);
}
}
function setIframeHeight(reHeight) {
var iframe = document.getElementById('tab1If')
if (iframe) {
var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
if (iframeWin.document.body) {
iframe.height = reHeight;
}
}
reSizeParentIframe()
};
</iframe>
</iframe>
//最底层的home.jsp的代码
//子页面重新修改父页面iframe高度
function reSizeParentIframe() {
var realHeight = 0;
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 + 35;
} else if (navigator.userAgent.indexOf("MSIE") > 0) { // IE
var bodyScrollHeight = window.document.body.scrollHeight + 21;
var elementScrollHeight = window.document.documentElement.scrollHeight + 1;
realHeight = Math.max(bodyScrollHeight, elementScrollHeight); //取当中比较大的一个
} else {//其他浏览器
realHeight = window.document.body.scrollHeight +
window.document.body.clientHeight + 1;
}
if (realHeight < 450) {
realHeight = 450;
}
//调用父页面的方法
parent.setIframeHeight(realHeight);
}