2008-09-12 88 views
8

我有一个应用程序,我想嵌入我们公司的CMS内。唯一的方法来做到这一点(我被告知),是加载在。<iframe> - 如何显示参考页面的整个高度?

简单:只需设置heightwidth100%!除此之外,它不起作用。

我没有找到有关设置frameborder0,所以它至少看起来喜欢的网站的一部分,但我不希望有一个丑陋的滚动条是媒体链接有一个页面。

你知道这样做的任何技巧吗?

编辑:我想我需要在一定程度上澄清我的问题:

  • 公司CMS显示通过CMS
  • 我的应用程序创建
  • 大多数页面对我们整个网站的绒毛和东西不是,但他们会让我把它嵌入到
  • 我无法控制iframe,所以任何解决方案都必须从引用的页面上工作(根据在iframe标签的属性)
  • 的CMS显示页脚,所以高度设置为1万个像素是不是一个好主意

我可以从引用的页面访问父页面的DOM?这可能会帮助,但我可以看到一些人可能不希望这是可能的...

这种技术似乎工作(gleaned从多个来源,但接受的答案被link启发:

在父文档:

<iframe id="MyIFRAME" name="MyIFRAME" 
    src="http://localhost/child.html" 
    scrolling="auto" width="100%" frameborder="0"> 
    no iframes supported... 
</iframe> 

在孩子:

<!-- ... --> 
<body> 
<script type="text/javascript"> 
    function resizeIframe() { 

     var docHeight; 
     if (typeof document.height != 'undefined') { 
      docHeight = document.height; 
     } 
     else if (document.compatMode && document.compatMode != 'BackCompat') { 
      docHeight = document.documentElement.scrollHeight; 
     } 
     else if (document.body 
      && typeof document.body.scrollHeight != 'undefined') { 
      docHeight = document.body.scrollHeight; 
     } 

     // magic number: suppress generation of scrollbars... 
     docHeight += 20; 

     parent.document.getElementById('MyIFRAME').style.height = docHeight + "px";  
    } 
    parent.document.getElementById('MyIFRAME').onload = resizeIframe; 
    parent.window.onresize = resizeIframe; 
</script>    
</body> 

BTW:这只适用于父母和孩子由于JavaScript安全原因限制在同一个域中...

回答

0

我可能失去了一些东西,但加入scrolling=no至于iframe标签通常摆脱了滚动条的属性。

+1

是的,但如果嵌入式页面不适合在iframe中被切断。 – 2008-09-12 14:13:48

2

假设您的iframe与包含页面位于同一台服务器上,您可以access it via javascript

对于setting the iframe to the full height of the contents有几种建议的方法,每种方法都有不同程度的成功 - 这个问题的谷歌显示这是一个相当普遍的方法,没有真正的,一刀切的共识解决方案我是害怕!

有几个人报告说,this script是诀窍,但可能需要some modification为您的具体情况(再次,假设您的iframe和父页面在同一个域)。