【问题标题】:<frameset> object sometimes not accessible in IE 8<frameset> 对象有时无法在 IE 8 中访问
【发布时间】:2019-10-22 13:48:12
【问题描述】:

我有一个带有两个子框架的框架集。

<frameset rows="241px,*" id="header_fr">
    <frame src="frame1.htm"/>
    <frame src="frame2.htm"/>
</frameset>

我将frame1.htm 用作标题,每次在frame2.htm 中更改内容时,我都会动态更改其大小。

我使用parent.document.getElementsByTagName("frameset")[0].rows = new_size + ",*"; 更改frame1.htm 的大小

一切正常,但有时parent.document.getElementsByTagName("frameset")[0] 不再可用,它为空或不是对象。这个问题的原因是什么?

【问题讨论】:

    标签: javascript html internet-explorer frames frameset


    【解决方案1】:

    你如何使用 JavaScript 函数?可能是 DOM 没有完全加载导致问题。您应该确保在对象完全加载后执行该函数。

    我使用下面的代码进行测试,它在 IE 8 中运行良好,你可以检查一下:

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
        <frameset rows="241px,*" id="header_fr">
            <frame src="frame1.htm" />
            <frame src="frame2.htm" />
        </frameset>
    </html>
    

    frame1.htm

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body style="background-color:aquamarine">
        111
    </body>
    </html>
    

    frame2.htm

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body style="background-color:burlywood">
        222
        <script>
            parent.document.getElementsByTagName("frameset")[0].rows = 40 + ",*";
        </script>
    </body>
    </html>
    

    【讨论】:

    • frame2.htm 中的 动态 内容更改是否可能导致 parent.htm 中的 DOM 重新呈现?如果是真的,我如何检查重新渲染何时完成?
    • 这取决于您如何加载动态内容:是重新加载整个页面还是仅重新加载更改的部分。此外,您可以使用window.onload 来检查 DOM 是否准备就绪。该函数将在整个页面加载时触发。更多信息可以参考this thread
    猜你喜欢
    • 2021-01-06
    • 2021-03-16
    • 2017-05-23
    • 2021-07-04
    • 2012-07-07
    • 1970-01-01
    相关资源
    最近更新 更多