自动获取iFrame的高度,父iframe取得子iframe的form

function iFrameHeight(ifm) {

//var ifm = document.getElementById('iframeBox4');
//var subWeb = document.frames ? document.frames["iframeBox4"].document : ifm.contentDocument; // IE和其他浏览器兼容选择
//if (ifm != null && subWeb != null) {
//ifm.height = subWeb.body.offsetHeight; //offsetHeight 页面高度
//}
if (ifm) {
var iframeWin = ifm.contentWindow || ifm.contentDocument.parentWindow;
if (iframeWin.document.body) {
ifm.height = iframeWin.document.documentElement.scrollHeight || iframeWin.document.body.scrollHeight;
}
}
}

<div>
<iframe name="iframe" id="iframeBox1" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>

<iframe name="iframe" id="iframeBox2" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>
<iframe name="iframe" id="iframeBox3" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>

<iframe name="iframe" id="iframeBox4" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>

<iframe name="iframe" id="iframeBox5" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>

<iframe name="iframe" id="iframeBox6" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>

<iframe name="iframe" id="iframeBox7" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>

<iframe name="iframe" id="iframeBox8" frameborder="0" width="100%" height="100%" scrolling="auto "
src="" style="display: none"
style="overflow-x: hidden; overflow: auto;" onload="iFrameHeight(this);"></iframe>
</div>

=======父iframe取得子iframe的form==========start============

//先清空之前的缓存,在保存最新的内容审核干部人事档案

var iframeBox4_iframe = document.getElementById('iframeBox4').contentWindow;
var iframeBox4_div =iframeBox4_iframe.document.getElementById('zzzkcGbthSaveForm');
var iframeBox41_div =iframeBox4_iframe.document.getElementById('zzzkcSaveForm');

// 缓存数据
localStorage.zzzkcGbthSaveForm=decodeURIComponent($(iframeBox4_div).serialize(),true);
localStorage.zzzkcSaveForm=decodeURIComponent($(iframeBox41_div).serialize(),true);

=======父iframe取得子iframe的form====end==================

猜你喜欢

转载自www.cnblogs.com/konglxblog/p/10011994.html