接下来,我们将编写JavaScript代码来计算iframe的高度。以下是script.js的代码: functionadjustIframeHeight(){variframe=document.getElementById('myIframe');// 获取iframe元素iframe.onload=function(){// 监听iframe加载完成事件variframeBody=iframe.contentWindow.document.body;// 获取iframe的bodyvarheight=iframeBody...
Html<iframename="container_ifranme"id="iframeId"scrolling="no"frameborder="no"border="0"src="home.html"onLoad="iFrameHeight()"></iframe>JsfunctioniFrameHeight(){varifm=document.getElementById("iframeId");varsubWeb=document.frames?document.frames["iframeId"].document:ifm.contentDocument;if(ifm!
mFrame.height = hTable; if(window.mainFrame.moduleRight != null){ //表示该内嵌页,包含内嵌的页面,页iframe的id固定为moduleRight。 initFrameHeight(mFrame,hTable); } } /** * 获取当前页面的高度 */ function getBodyHeight(doc){ if(doc.all) return doc.body.offsetHeight; else return doc.bod...
pTar=document.getElementById(iframename); 11 } 12 else 13 { 14 eval('pTar ='+iframename+';'); 15 } 16 if(pTar&&!window.opera) 17 { 18 //begin resizing iframe 19 pTar.style.display="block" 20 if(pTar.contentDocument&&pTar.contentDocument.body.offsetHeight) 21 { 22 //ns6 sy...
JavaScript自动设置IFrame高度(兼容各主流浏览器) 调用方式如下 代码语言:javascript 复制 <iframe id="ifm"name="ifm"onload="SetIFrameHeight('ifm')"src="http://www.qq.com"/> 代码语言:javascript 复制 functionSetIFrameHeight(down){varSys={};varua=navigator.userAgent.toLowerCase();vars;(s=ua.match...
我是你们的朋友全栈君。 Demo页面:主页面 iframe_a.html ,被包含页面 iframe_b.htm 和 iframe_...
contentDocument.body.offsetHeight; else if (dyniframe[i].Document && dyniframe[i].Document.body.scrollHeight) //如果用户的浏览器是IE dyniframe[i].height = dyniframe[i].Document.body.scrollHeight; } } //根据设定的参数来处理不支持iframe的浏览器的显示问题 if ((document.all || document.get...
<script type="application/javascript"> function resizeIFrameToFitContent( iFrame ) { iFrame.width = iFrame.contentWindow.document.body.scrollWidth; iFrame.height = iFrame.contentWindow.document.body.scrollHeight; } window.addEventListener('DOMContentLoaded', function(e) { var iFrame = document.getElement...
在iframe完全加载后即onload,调用setIframeHeight(),iframe内容加载完成后,可获取iframe的高度值,然后重新设置iframe的高度,以下是整理好的代码: function setIframeHeight(id) { var ifrm = document.getElementById(id); var doc = ifrm.contentDocument? ifrm.contentDocument: ifrm.contentWindow.document; ifrm.sty...
javascript 中iframe高度自适应(同域) 今天解决了iframe高度自适应的问题,不过这只是同域下的页面嵌入,以下是代码: functionSetCwinHeight(){variframeid =document.getElementById("frame");//frame是iframe的idif(document.getElementById) {if(iframeid && !window.opera) {if(iframeid.contentDocument&& iframe...