繁体   English   中英

在iframed页面中的.toggle上重新调整iframe大小

[英]Re-sizing iframe size on .toggle in iframed page

我浏览过类似的文章,但没有发现与我的情况真正相关的任何内容。

我有我总结页面iframe ,用户已经通过所乘的路线摘要页几页。 在每张正在准备的页面中。 我正在使用.toggle扩展/折叠页面的内容。

我发现的问题是,当摘要页面首次加载时,我正在使用脚本来使iframe达到其所包含页面内容的大小,但是当我单击以切换该内容并将其折叠时,它将iframe的大小保持不变,因此会有大量空白。

我猜想我需要从包含的页面发送回摘要页面,以表明内容大小已更改,因此要重新调整iframe大小,但不确定如何执行此操作。

有人可以指出正确的方向吗?

文件的示例是...

Parent.html

<link rel="stylesheet" type="text/css" href="styles.css" />
<script type="text/javascript">        
    // Resize an iframe so it's as tall as its contents. This could be much shorter but is expanded for clarity.
    function size_frame(frame_name, frame_id)
    {
       // Get the iframe element
       var frame_element = document.getElementById(frame_id);           
       // Get the iframe frame-window object. Note this has different properties to frame_element.
       var frame_window = frames[frame_name];           
       // Set the height to 1px first, because some browsers will give you the maximum height of either the
       // frame or its contents, when you try to read the scrollHeight property as we do below.
       frame_element.style.height = "1px";           
       // set the height of the iframe element to the "scrollHeight" of the document element of the frame window.
       frame_element.style.height = frame_window.document.documentElement.scrollHeight +"px";           
    }    
</script>
<h1>SUMMARY</h1>
<table border="0" cellspacing="0" cellpadding="0" width="850">
    <tr>
        <td><iframe src="child1.html" width="850" frameborder="0" scrolling="no" name="child1" id="child1" onload="size_frame('child1','child1');"></iframe></td>
    </tr>
</table>

Child.html:

<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript">
    $().ready(function () {
        $('th[event-type-header]').bind('click', function () {
            var eventType = $(this).attr('event-type-header');
            $('tr[event-type="' + eventType + '"]').toggle('hide-event-type');
        });
    });
</script>
<h1>Child Page</h1>

<table width="800" border="0" cellspacing="0" cellpadding="0" class="content">
    <tr>
        <th class="content" event-type-header="childPage">
            Header <img src="arrow_down.gif" align="right" width="15" />
        </th>
    </tr>
    <tr class="content2" event-type="childPage">
        <td align="center">
            <table width="750" cellpadding="0" cellspacing="0" class="content">
                <tr>                        
                    <th class="content" colspan="2">Sub Heading</th>
                </tr>
                <tr class="content2">
                    <td>
                        Some Text           
                    </td>
                </tr>                           
            </table>
        </td>
    </tr>
</table>

您需要使用offsetHeight,而不是scrollHeight。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM