ITeye博客

iframe自适高度

berrywu · 2010-03-24 16:10 · HTML技术 · 编程语言 · Markdown

<iframe width="100%" id="autoHeightIframe" src="URL必须和该文件在同一个域名下"
       onload="Javascrīpt:setIframeHeight(this)" frameborder="0" scrolling="no" height="100%">
</iframe>

 

<script>
function setIframeHeight(iobj) {
 var win = iobj;
 if (document.getElementById("autoHeightIframe")) {
  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;
   }
  }
 }
} 
</script>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。