Total height of the html document loaded in TWebBrowser

I want to know how to get the TOTAL height of the html document loaded into the TWebBrowser component (Delphi)?

I found something like this and it does not work:

webbrowser.oleobject.document.body.scrollheight

I placed it inside the OnDocumentComplete event.

I need height because I am calculating the PageSize ScrollBar property (my custom scrollbar - the embedded WebBrowser is disabled), which depends on the height of the web page.

Thanks for any feedback, best wishes

+4
source share
1 answer

Something like this should work:

uses MSHTML;

var
  HtmlElement: IHTMLElement2;
  PageHeight: Integer;

begin
  with MyWebBrowser.ControlInterface do
  begin
    HtmlElement := (Document as IHTMLDocument3).documentElement as IHTMLElement2;
  end;

  PageHeight := HtmlElement.scrollHeight;
end;

. body, , (, ):

var
  BodyElement: IHTMLElement2;
  PageHeight: Integer;

begin
  with MyWebBrowser.ControlInterface do
  begin
    BodyElement := (Document as IHTMLDocument2).body as IHTMLElement2;
  end;

  PageHeight := BodyElement.scrollHeight;
end;
+2

All Articles