Results 1 to 11 of 11

Thread: WebBrowser control and iframes

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    WebBrowser control and iframes

    I'm trying to get hold of the iframe elements and its content.

    Basically, there is a site which has a webpage and within it, it has alot of elements (divs etc...) and within it, an iframe. I can see all the content in the iframe via the developer toolbar and also the view source no problem.

    The thing is I need to "interrogate" the iframe and its content but cannot seem to find out a way of doing this using the webbrowser control. it works fine for non iframe stuff I guess. The closest match ive been able to get is the iframe element.

    The HTML tags/code in developer toolbar looks something like the following:

    Code:
    ..
    ..
    <body>
    <div id="pagelet_presence">
    <div id="blueBar" />
    <div id="globalContainer">
    <div class="sitecontent clearfix" id="content">
    <div id="mainContainer">
    <div id="contentCol">
    <div id="contentArea">
    <div id="pagelet_canvas_content">
    <div id="pagelet_iframe_canvas_content">
    <div>
    
    <iframe name="iframe_canvas_https" height="600".................>
    <!DOCTYPE html public..............>
    <html>
    <head>
    <body>
    <div id="demoWrapper">
    ..
    ..
    ..
    </div>
    </body>
    </head>
    </html>
    </div>
    </div>
    ..
    ..

    so its a main page with loads of divs and within it it eventually gets down to the iframe which is serving up some site but cannot obtain the site its serving as there is no indication of it at all.

    Anyway, does anyone have any ideas AT ALL on how I can get into the iframe content?

    the code ive currently got is simple, and can get up to the "iframe_canvas_https" element and not anything below that which is where I need to go to get the "demoWrapper" div elements.

    doing a simple "this.webBrowser.Document.GetElementById("demoWrapper")" does not bring back anything.

    Code:
    HtmlElement potentialIFrame = this.webBrowser.Document.GetElementById("iframe_canvas_https");
    is the current code.

    its getting frustrating. I just want to get elements within that iframe. And yes, the page has been loaded fully at this point.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  2. #2
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: WebBrowser control and iframes

    GetElementById only retrieves elements with the corresponding 'id' tag.
    What you seem to be referring to is the 'name' tag.

    I'm not big on the HTML DOM but I think you might get something with this:
    Code:
    window.frames["iframe_canvas_https"].document
    Delete it. They just clutter threads anyway.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: WebBrowser control and iframes

    well yes, thats fine. I can get that... and I know what GetElementById does.... but the problem is, I cannot seem to get past "iframe_canvas_https" at all.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  4. #4
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: WebBrowser control and iframes

    I'm no expert at this...

    I don't think you can find the element with the demowrapper Id because you are looking at the wrong document.

    As far as I know the webbrowser control does not have any support for the frames collection where one would normally find the other documents.

    Does this output the elusive URL you are looking for?
    Code:
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                Console.WriteLine("Document Complete: {0}", e.Url);
                if (e.Url == webBrowser1.Url)
                {
                    Console.WriteLine("finally!");
                }
            }
    W o t . S i g

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: WebBrowser control and iframes

    oh yeh it does for sure.
    The page itself is embedded in an IFRAME I believe.

    so close yet so far!

    I thought it would be able to access the elements as long as you have the IFRAME document reference, which I believe I have but it does not find anything I tell it, even tho the dev toolbar shows otherwise

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  6. #6
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: WebBrowser control and iframes

    I think the dev toolbar might be showing you all the documents inline, whereas the webrowser.Document just gets you the top level document.

    This is a guess
    Code:
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
                if (e.Url == webBrowser1.Url)
                {
                    foreach (HtmlWindow window in webBrowser1.Document.Window.Frames)
                    {
                        var element = window.Document.GetElementById("demoWrapper");
                        if (element!= null)
                        {
                            Console.WriteLine("Gotcha!");
                        }
                    }
    
                }
            }
    W o t . S i g

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: WebBrowser control and iframes

    good catch about the .Window.Frames.... forgot about that! Will try...

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: WebBrowser control and iframes

    hmm. nope

    it says 4 frames but the 3/4th frame throws an unauthorised exception.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  9. #9
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: WebBrowser control and iframes

    How do you feel about posting (or PMing) the url?
    W o t . S i g

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: WebBrowser control and iframes

    would feel uncomfortable either way! lol.

    its a private internal site which is scattered across the globe and due to internal circumstances, this is the last resort I have of getting the required data from the forms programmatically

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  11. #11
    New Member
    Join Date
    Mar 2014
    Posts
    2

    Re: WebBrowser control and iframes

    Hi, I'm facing issue in fetching the links (or) get the controls inside IFrame. Can someone suggest me solution.

    Thanks inadvance for your response.
    Last edited by PoornimaKamal; Apr 4th, 2014 at 07:04 AM. Reason: addition

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width