maxedmelon
maxedmelon

Reputation: 251

TWebBrowser - Hook receive event

I am trying to automatically submit a form, and save the resulting image that gets shown in the TWebBrowser object.

The image gets loaded over several chained javascript requests (ajax), until it finally appears in the document.

What is the best way to get this image? I thought of hooking the receive function to be able to see the http response (which would basically be my image).

Another possibility could be to load the image from cache / memory...

I don't have any idea how to practically do this, I hope someone can help.

Thanks.

Upvotes: 0

Views: 2931

Answers (3)

Tavel
Tavel

Reputation: 73

To be more scalable with your application you can directly try EmbeddedWB. It wraps IWebBrowser2 and very handy to use. Embarcadero use EmbeddedWB in their RADStudio.

Upvotes: 1

RRUZ
RRUZ

Reputation: 136391

you can retrieve all the url images using the images property from the IHTMLDocument2 object.

see this sample using the OnDocumentComplete Event.

procedure TForm2.WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant);
var
HTMLDocument2: IHTMLDocument2;
i            : Integer;
Item         : IHTMLElement;
ImageUrl     : string;
begin
    HTMLDocument2 := (WebBrowser1.Document AS IHTMLDocument2);
    for i := 0 to HTMLDocument2.images.length -1 do
    begin
    Item := HTMLDocument2.images.item(i, null) As IHTMLElement;
    ImageUrl:=item.getAttribute('src',0);
     //do your stuff with the url image retrieved
    end;
end;

Upvotes: 1

Francesca
Francesca

Reputation: 21640

You can use the OnDocumentComplete or OnNavigateComplete2 events (see the SHDocVw help) or wait for the WebBrowser to be in a ReadyState READYSTATE_COMPLETE and then read from the WebBrowser.Document.

But you can also (simpler IMO) use a TIdHTTP.Get to directly get the response stream.

Upvotes: 1

Related Questions