DelphiFAQ Home Search:

Scroll a TWebBrowser document to the top/ bottom/ right


comments5 comments. Current rating: 5 stars (4 votes). Leave comments and/ or rate it.


My application uses TWebBrowser and I need to load a document and then have TWebBrowser scroll to the bottom of the document. How can I achieve this?


Create an event on OnDocumentComplete event TForm1.WebBrowser1DocumentComplete() and put this code in there:

WB_ScrollTo(WebBrowser1, wbPosBottom);

// Scroll to the Bottom, Top, Right of the Document:
  TWBPosition = (wbPosBottom, wbPosTop, wbPosRight);

function WB_ScrollTo(WB: TWebBrowser; Position: TWBPosition): Boolean;
  ParentW: OLEVariant;
  Result := WB.Document <> nil;
  if Result then
    ParentW := WB.OleObject.Document.ParentWindow;
    case Position of
      wbPosBottom: ParentW.ScrollTo(0, ParentW.Screen.Height);
      wbPosTop: ParentW.ScrollTo(0, 0);
      wbPosRight: ParentW.ScrollTo(ParentW.Screen.Width, 0);

procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
  WB_ScrollTo(WebBrowser1, wbPosBottom);

Content-type: text/html


2006-03-26, 03:55:38
anonymous from Poland  
2006-04-08, 13:39:43
anonymous from United States  
You, sir, are a godsend.
2007-05-27, 04:54:23
anonymous from United Kingdom  
The scroll to bottom doesn't work perfectly - I have a case here when the page is very long, and the WB_ScrollTo(WebBrowser1, wbPosBottom); doesn't scroll all the way down, just down by the height of the screen. i.e. by 'ParentW.Screen.Height'
2009-08-28, 03:18:52
from Hungary  
That's true, Bottom has some problems.
Not a beauty solution, but if you use a big value (e.g. 10000) instead of ParentW.Screen.Height. It works:).
2015-06-21, 05:03:06
anonymous from United Kingdom  
Thank you for this! It works a treat!



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: