Search code examples
internet-exploreriframeframesihtmldocument2

IHTMLDocument2 / IHTMLDocument3 frames counts are different


I'm trying to use some IE automation to process various internal webpages. Some of those pages use iframes and frames, so we need to be able to process inside those frames as well.

I've come across issues if the frames or iframes don't display content in the same domain as the parent document and this is fine.

However, something else has appear which I can't figure out.

If I visit (For example) http://www.gmail.com/ and goto the login page, using the IHTMLDocument2.frames.length returns 1, even when there are no iframes present. IHTMLDocument3.getElementsByName("iframe").length returns 0 as expected.

This only seems to happen on IE9. IE6 and IE7 work as we expect, and we've not yet tested on IE8.

Does anyone have any insite into why this happens? Obviously one is counting the actual tags, but where is ITHMLDocument2.frames.length getting 1 from all the time? Is it a security setting, etc... ?


Solution

  • According to my Inspect Element in Chrome (mac here can't test IE), gmail has at least 5 iframes, this is the first one right below the body tag and a few below that.

    <iframe style="position: absolute; width: 9em; height: 9em; top: -99em; " tabindex="-1" aria-hidden="true"></iframe>
    

    Perhaps the DOM you're parsing is the source of one of these Iframes rather then the outer page itself ?

    Indeed, one of the iframes has got a child iframe, but others haven't; this might be why the IHTMLDocument is behaving differently, but that's just a guess...

    You have to remember though, both of these interfaces are ancient, IE4 and 5 respectively.