【问题标题】:Is there a way to make an Iframe expandable as needed?有没有办法根据需要使 iframe 可扩展?
【发布时间】:2013-12-12 17:18:52
【问题描述】:

有没有办法根据需要使 iframe 可扩展?我有一个带有 iframe 的网页到同一服务器上的第二个网页。第二个网页有一个可展开的表格。我想要的是当有人通过 iframe 查看第二页并单击表格展开时,iframe 也会展开以适应大小。

【问题讨论】:

    标签: c# javascript html asp.net iframe


    【解决方案1】:
    <script type="text/javascript">
    //<![CDATA[
    window.onload = function() {
    var f = document.getElementById("mainframe");
    function resize() {
    var h = "";
    var w = "";
    if (f.contentDocument) {
    h = f.contentDocument.documentElement.offsetHeight + 20 + "px";
    (f.contentDocument.documentElement,"").getProperty Value
    
    ("width");
    } else if (f.contentWindow) {
    h = f.contentWindow.document.body.scrollHeight + 5 + "px";
    } else {
    return;
    }
    f.setAttribute("height",h);
    f.parentNode.setAttribute("height",h);
    }
    if (window.addEventListener) {
    f.onload = resize;
    } else if (f.attachEvent) {
    f.attachEvent("onload", resize);
    } else {
    return;
    }
    resize();
    }
    //]]>
    </script>
    
    <iframe name="frm" id="mainframe" src="URL HERE" frameborder="0" allowtransparency="no" scrolling="no" target="_self" height="150"></iframe>
    

    这是 HTML 代码:

    <a href="URL OF PAGE" target="content">Name Of Page</a>
    

    【讨论】:

      【解决方案2】:

      如果页面在同一个域中,那么下面的解决方案应该可以工作。

      Make iframe automatically adjust height according to the contents without using scrollbar?

      【讨论】:

        猜你喜欢
        • 2020-08-10
        • 2012-12-15
        • 2021-08-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-03-16
        • 2012-09-08
        • 1970-01-01
        相关资源
        最近更新 更多