Problems with WebBrowser objects...

Hi there!

Could someone please explain why the following three functions return the same value

WebBrowser_instance.Document.Body.GetAttribute("scrollHeight")

WebBrowser_instance.Document.Body.GetAttribute("clientHeight")

WebBrowser_instance.Document.Body.GetAttribute("offsetHeight")

I really need the object to return the right scrollHeight values.

Regards, O



Answer this question

Problems with WebBrowser objects...

  • Lovens

    thanks again.
  • Attila Fogel

    That's exactly my point!!

    The numbers should be there...

    I just don't get it .... if there's an object that has (has got to have) an event handler that sets the scroll bars dynamically to some value (relative to it's contents), there MUST be some throwback for the scrollbars. !!!!!!!!! ----- !!!!!! BUT THERE IS NONE AT DISPOSAL!!!!!! ---- !!!!! And it just makes me mad to post this question all around the web (sure... I did the step to step debugging) ... with the same results... (btw.: is the readyState readOnly or am I lame !). I'm starting to think that the object has been constructed without the most meaningful function... PLEASE tell me - no teach me - I'm wrong!!

    Loeve to all, O

    P.S.: ok... I have settled down a little bit. What I'm trying to say is... Please - more than i bag you - I urge you: Create a fresh Windows application (VB2005). Throw a WebBrowser object to the form. Navigate to some URL, that has the height larger than your screen-size. Now - please - how the &#$% can you possibly get that height - the height of the body, or whatever DOM objects that creates the document! Get me the answer, I'll fly a beer over to your address - I promise (likely it's pretty good ;])!!


  • yem

    Hi again!

    Maybe I wasn't specific enough the first time what my problem is all about...

    I created a WebBrowser object. Let's say it's width and height are both set to 500, respectively. When I navigate the browser to some site, the document inside is shown and the browser's vscroll and hscroll are shown. The document is about 3000px high and 780px wide. I haven't found one single method, function or event handler that would get me on the right track to read off these two values. That's why I relied on the functions mentioned in the first post and they all return the same value. I even tried to get access to the webbrowser's vscroll and hscroll, with no success.

    please help me out on this one.

    Thanks, O


  • brad.p

    I guess that's why people hate webpages that have frames in them

    No need to send me beer, because I think my postman drinks all my beer-mails (they never get through to me, anyway)


  • Michael Tsai

    Hi, if you want the dimensions of the webpage, then I think this Rectangle will give you that:

    WebBrowser1.Document.Body.ScrollRectangle

    with these two giving you the amounts that the page is scrolled:
    WebBrowser1.Document.Body.ScrollTop
    WebBrowser1.Document.Body.ScrollLeft

    and if you want the visible size of the webbrowser control (so size - scrollbarsizes), then it's this one:

    WebBrowser1.Document.Body.ClientRectangle




  • Jessica Alba

    Put this code into a new project and run it:

  • EwenTweedie

    It's hard to figure out exactly which set of numbers you're looking for - to me, the Body.ScrollRectangle seems to be the size of the webpage, not the smaller visible part, with ScrollTop showing the amount that's hidden at the top.

    If you have an idea of what the exact numbers should be, then why not set a breakpoint somewhere in your code and examine the WebBrowser's properties in the Locals window - they've got to be in there somewhere

    EDIT: Make sure the document is complete:
    WebBrowser1.ReadyState = WebBrowserReadyState.Complete

  • Kyco

    Thanks for the reply, that's not the solution though.

    the ScrollRectangle returns the visible dimensions (not the whole body dimensions), the ScrollTop and the ScrollLeft allways give me the scrollable positions, wich are in my case 0,0 , respectively.

    The clientRectangle returns what's to be expected - the same as the ScrollRectangle as my webbrowser is docked to the frame (and yes, I have tried to undock it and turn the parent form autoscroll to true)

    nogChoco: thanks for taking the time.

    Any other ideas, any at all... even ones for a workaround - greatly appreciated!

    Regards, O


  • Jerod Moemeka

    Sir, I salute you!

    I failed on a basic principle... The whole time I tried to get the values from a web page that loads inside a <frame> :]]]]]]

    Thank you so much for taking the time, all I need is your address and the beer is off ;]

    Regards, O


  • Problems with WebBrowser objects...