首页 > 代码库 > iframe 的onload有时不起作用
iframe 的onload有时不起作用
<script>
window.onload = function (){
var iframeB = document.getElementById("iframepage");
var iframepage = document.createElement(‘iframe‘);
iFrameHeight("load");
//document.body.appendChild(iframepage);
iframeB.appendChild(iframepage);
}
//ifram高度自适应
function iFrameHeight() {
var bodyHeight = 460;
if (/msie/.test(navigator.userAgent.toLowerCase()) || /firefox/.test(navigator.userAgent.toLowerCase())) {
bodyHeight = window.frames["iframepage"].document.body.scrollHeight;
}
else {
bodyHeight = document.getElementById("iframepage").contentWindow.document.documentElement.scrollHeight;
}
document.getElementById("iframepage").height = bodyHeight;
}
</script>
html
<div id="rl">
<iframe id="iframepage" name="iframepage" frameBorder=0 scrolling=no onl oad="iFrameHeight()" width="280" src=http://www.mamicode.com/‘#/‘" /cart/cart_calendar_iframe?oneday=".(empty($oneDay)?‘‘:$oneDay))?>"></iframe>
</div>
iframe 的onload有时不起作用