WebBrowser执行脚本

ExecuteJavaScript(WebBrowser:TWebBrowser; Code: string):Variant;
var //发送脚本
Document:IHTMLDocument2;
Window:IHTMLWindow2;
begin
// execute javascript in webbrowser
Document:=WebBrowser.Document as IHTMLDocument2;
if not Assigned(Document) then Exit;
Window:=Document.parentWindow;
if not Assigned(Window) then Exit;
try
Result:=Window.execScript(Code,'JavaScript');
except
on E:Exception do raise Exception.Create('Javascript error '+E.Message+' in: '#13#10+Code);
end;
end;

posted @ 2016-08-22 20:51  findumars  Views(832)  Comments(0Edit  收藏  举报