1

I have a frameset with two child frames.

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

I use frame1.htm just as a header and I change its size dynamically every time content is changed in frame2.htm.

I change the size of frame1.htm using parent.document.getElementsByTagName("frameset")[0].rows = new_size + ",*";

Everything is working fine, but sometimes parent.document.getElementsByTagName("frameset")[0] is no longer available, it's null or not an object. What can be the reason for this problem?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
ML ML
  • 61
  • 1
  • 7

1 Answers1

1

How do you use the JavaScript function? It might be the DOM hasn't loaded completely that caused the issue. You should ensure that the function is executed after the object being fully loaded.

I use the code like below to test and it works well in IE 8, you could check it:

<!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>
Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • Is it possible **dynamic** content changing in `frame2.htm` to cause DOM rerendering in the `parent.htm`? And if it is true, how can I check when rerendering is done? – ML ML Oct 23 '19 at 09:54
  • 1
    It depends on how you load the dynamic content: if you reload the whole page or only reload the part changed. Besides, you could use `window.onload` to check if the DOM is ready. The function will be fired when the whole page loads. For more information, you could refer to [this thread](https://stackoverflow.com/questions/588040/window-onload-vs-document-onload). – Yu Zhou Oct 24 '19 at 02:53