<iframe name="iframe_content" id="iframe_content" width="100%" scrolling="no" onload="this.height=contentWindow.document.documentElement.scrollHeight"></iframe>
其中:
iframe适应主容器宽度:width="100%"
取消滚动条:scrolling="no"
子页撑开iframe:
- onload = " this.height=contentWindow.document.documentElement.scrollHeight "
- js:
-
function iframeHeight(id){ try{ var iframe = document.getElementById(id); //IE用attachEvent 判断子页面是否加载完成。 if(iframe.attachEvent){ iframe.attachEvent("onload", function(){ iframe.height =iframe.contentWindow.document.documentElement.scrollHeight; }); return; }else{ //3C用onload来判断子页面是否加载完成。 iframe.onload = function(){ iframe.height = iframe.contentDocument.body.scrollHeight; }; return; } }catch(e){ throw new Error('iframeHeight Error'); } }