文档详情

iframe自适应高度方法.doc

发布:2017-06-16约6.29千字共6页下载文档
文本预览下载声明
简单一点给每个iframe外面套个div就可以了 diviframe id=dingbu name=dingbu width=100% onload=this.height=dingbu.document.body.scrollHeight frameborder=0 src=spms/01.shtml/iframe/div function SetWinHeight(obj) { var win=obj; if (document.getElementById) { if (win !window.opera) { if (win.contentDocument win.contentDocument.body.offsetHeight) win.height = win.contentDocument.body.offsetHeight; else if(win.Document win.Document.body.scrollHeight) win.height = win.Document.body.scrollHeight; } } } 最后,加入iframe,不能丢掉onload属性,当然了,id也必须也函数中的win匹配 复制代码 代码如下: iframe width=778 align=center height=200 id=win name=win onload=Javascript:SetWinHeight(this) frameborder=0 scrolling=no src=1.htm/iframe 这么的这种也是跟上面的解决方法类似的代码 经典代码 iFrame 自适应高度,在IE6/IE7/IE8/Firefox/Opera/Chrome/Safari通过测试。 HTML代码: 复制代码 代码如下: iframe src=/ id=iframepage name=iframepage frameBorder=0 scrolling=no width=100% onLoad=iFrameHeight() /iframeJavascript代码: script type=text/javascript language=javascript 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; } } /script 下面这个兼容性更好一些 复制代码 代码如下: script language=javascript type=text/javascript function dyniframesize(down) { var pTar = null; if (document.getElementById){ pTar = document.getElementById(down); } else{ eval(pTar = + down + ;); } if (pTar !window.opera){ //begin resizing iframe pTar.style.display=block if (pTar.contentDocument pTar.contentDocument.body.offsetHeight){ //ns6 syntax pTar.height = pTar.contentDocument.body.offsetHeight +20; pTar.width = pTar.contentDocument.body.scrollWidth+20; } else if (pTar.Document pTar.Document.body.scrollHeight){ //ie5+ syntax pTar.height = pTar.Document.body.scrollHeight; pTar.width = pTar.Document.body.scrollWidth; } } } /script iframe src =/default2.aspx frameborder=0 marginheight=0 marginwidth=0 fr
显示全部
相似文档