I need the correct page height of a WebBrowser control.
In Javascript, this works:
var body = document.body;
var html = document.documentElement;
var height = Math.max( body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight );
Duplicate questions exist on SO, with the the following methods suggested:
webBrowser.Document.Body.ScrollRectangle.Height;
webBrowser.Document.GetElementsByTagName("body")[0].OffsetRectangle.Bottom;
webBrowser.Document.GetElementsByTagName("body")[0].OffsetRectangle.Height;
Except none return the same value as the JS code.
I'm open to the possibility that the JS value is wrong but I am fairly confident it is correct because scrolling to the bottom of the page and adding the ScrollTop
position to the control height
produces the same value.
webBrowser1.Document.GetElementsByTagName("HTML")[0].ScrollTop + webBrowser1.Height;
For my particular case, C# is returning a height of 510, while JS returns correct height, 529. This inconsistency is throwing off a custom scroll bar I have written.