Francois,

Thanks, that solved many of the missing definitions, but there is still one
I haven't been able to track down.  The line:

  HTMLWin.execScript(JavaScriptExpression, 'JavaScript');

Causes an error because " JavaScriptExpression " is still not defined.
Something must be missing; do you have a definition for "
JavaScriptExpression"?

Thanks,
Rich
 
Sincerely,
Rich Cooper
EnglishLogicKernel.com
Rich AT EnglishLogicKernel DOT com

 

-----Original Message-----
From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf
Of Francois Piette
Sent: Wednesday, February 18, 2009 12:41 AM
To: Borland's Delphi Discussion List
Subject: Re: [TWebBrowser] Calling a JavaScript function

>What unit has to be in the "uses" clause to define the two vars:
>    Doc     : IHTMLDocument2; // Current HTML document
>    HTMLWin : IHTMLWindow2;   // Parent window of current HTML document

You need MSHTML, SHDocVw and ActiveX.

--
francois.pie...@overbyte.be
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be


-----Original Message-----
From: delphi-boun...@elists.org [mailto:delphi-boun...@elists.org] On Behalf
Of Francois Piette
Sent: Monday, February 16, 2009 7:25 AM
To: Borland's Delphi Discussion List
Subject: Re: [TWebBrowser] Calling a JavaScript function

> I have the following problem: Having a web page loaded into a TWebBrowser
> hosted in my Delphi application, I want to have Delphi code execute a
> JavaScript function embedded in the HTML page. How can I do that ?

Answering my own question:

procedure WB_ExecScript(WebBrowser: TWebBrowser; JavaScriptExpression :
String);
var
    Doc     : IHTMLDocument2; // Current HTML document
    HTMLWin : IHTMLWindow2;   // Parent window of current HTML document
begin
    Doc := WebBrowser.Document as IHTMLDocument2;
    if Assigned(Doc) then begin
        HTMLWin := Doc.parentWindow;
        if Assigned(HTMLWin) then begin
            try
                HTMLWin.execScript(JavaScriptExpression, 'JavaScript');
            except
                on E:Exception do begin
                    ShowMessage('Erreur d''exécution JavaScript de "' +
                                JavaScriptExpression + '"');
                end;
            end;
        end;
    end;
end;

--
francois.pie...@overbyte.be
Author of ICS (Internet Component Suite, freeware)
Author of MidWare (Multi-tier framework, freeware)
http://www.overbyte.be

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

_______________________________________________
Delphi mailing list -> Delphi@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

Reply via email to