I was doing some playing around with accessing frames on the DOM via window.top.frames, and noticed that the collection doesn't seem to be populated until after the actual <iframe> tag. My example:
var oFrames = window.top.frames;
alert("before: " + oFrames.length);
<iframe id="myframe" src="testing/jreese/test.asp" name="ok"></iframe>
alert("after: " + oFrames.length);
demonstrates how the count changes. Is there a better way to access frames/iframes rather than using the frames collection? If my findings are correct, does this mean you're not able to use the frames collection in a .js file that's included at the top of a page to access iframes that appear in the body of the page?
You don't attempt to access any DOM element until either you know it has been rendered, by virtue of the fact that your script renders below it, or you use an onload or document.onreadystatechange event handler to initialise your code after the DOM is complete.
I still remember the time when <script> tag was forbidden to appear on the document <head> completely.
the script element was allowed on the document head only for browser sniffing code.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)