<iframe> - 如何显示引用页面的整个高度?

Dar*_*mas 8 html iframe

我有一个应用程序,我想嵌入我们的公司CMS.(我被告知)这样做的唯一方法是将其加载到<iframe>.

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

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

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

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

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

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

这种技术似乎有效(从几个来源收集,但受到接受答案的链接的启发:

在父文件中:

<iframe id="MyIFRAME" name="MyIFRAME" 
    src="http://localhost/child.html"
    scrolling="auto" width="100%" frameborder="0">
    no iframes supported...
</iframe>
Run Code Online (Sandbox Code Playgroud)

在孩子:

<!-- ... -->
<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>
Run Code Online (Sandbox Code Playgroud)

顺便说一句:这只有在父和子因为安全原因限制JavaScript而在同一个域中时才有效...

ral*_*lfe 4

您可以只使用脚本语言将页面包含到父页面中,否则,您可能想尝试以下 JavaScript 方法之一:

http://brondsema.net/blog/index.php/2007/06/06/100_height_iframe http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_22840093.html