DelphiFAQ Home Search:
General :: Programming :: Delphi :: Network
Network (local network and Internet) programming under Windows with Delphi.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.

Featured Article

Scroll a TWebBrowser document to the top/ bottom/ right

Question:

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?

Answer:

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:
type
   TWBPosition = (wbPosBottom, wbPosTop, wbPosRight);
 
 function WB_ScrollTo(WB: TWebBrowser; Position: TWBPosition): Boolean;
 var
   ParentW: OLEVariant;
 begin
   Result := WB.Document <> nil;
   if Result then
   begin
     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);
     end;
   end;
 end;
 
 
 procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
   const pDisp: IDispatch; var URL: OleVariant);
 begin
   WB_ScrollTo(WebBrowser1, wbPosBottom);
 end;
 

Generated 0:01:16 on Aug 18, 2018