iframe自动适应高度1

王朝学院·作者佚名  2016-05-24
窄屏简体版  字體: 小  |  中  |  大  |  超大  

iframe自动适应高度1 js:

function iFrameHeight() {var ifm= document.getElementById("iframepage");var subWeb =document.frames ? document.frames["iframepage"].document : ifm.contentDocument;if(ifm != null && subWeb != null) {ifm.height = subWeb.body.scrollHeight;}}

iframe:

<iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="width:100%; " onLoad="iFrameHeight()"></iframe>

下面的兼容性比较好:/*兼容FF/IE9/IE8/IE7/IE6*/function iframeResize(iframe) { try { //var iframe = document.getElementById("contentFrame"); //("contentFrame"); var idocumentElement = iframe.contentWindow.document.documentElement; if (idocumentElement.scrollHeight > 560) { iframe.height -= 5; iframe.height = idocumentElement.scrollHeight; } else { iframe.height = 560; } } catch (e) { window.status = 'Error: ' + e.number + '; ' + e.description; } }

iframe:

<iframe id="iframepage" src="study_1.asp" frameborder="0" scrolling="no" style="width:100%; " onLoad="iframeResize(this)"></iframe>

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航