Code:
uses
MSHTML;
procedure TForm1.CallFoo(S: string; I: Integer);
{ Calls JavaScript foo() function }
var
Doc: IHTMLDocument2; // current HTML document
HTMLWindow: IHTMLWindow2; // parent window of current HTML document
JSFn: string; // stores JavaScipt function call
begin
// Get reference to current document
Doc := WebBrowser1.Document as IHTMLDocument2;
if not Assigned(Doc) then
Exit;
// Get parent window of current document
HTMLWindow := Doc.parentWindow;
if not Assigned(HTMLWindow) then
Exit;
// Run JavaScript
try
JSFn := Format('foo("%s",%d)', [S, I]); // build function call
HTMLWindow.execScript(JSFn, 'JavaScript'); // execute function
except
// handle exception in case JavaScript fails to run
end;
end;
More information can be found here.
Bookmarks