Delphi .NET (2) Database (71) Delphi IDE (89) Network (39) Printing (3) Strings (12) VCL (83) Windows with Delphi (280)
Exchange Links About this site Links to us 
|
Scroll a TWebBrowser document to the top/ bottom/ right
4 comments. Current rating: (3 votes). Leave comments and/ or rate it.
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);
 | |  | | 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;
| |  | |  |
Comments:
|
anonymous from Poland
|
 |
|
|
|
|
anonymous from United States
|
 |
|
|
You, sir, are a godsend.
|
|
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'
|
|
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:).
|
|