楼上的方法比较容易实现,下面的方法更通用:
// function to execute a script function
function ExecuteScript(WebBrowser: TWebBrowser; script: string; language: string = 'javascript'): Boolean;
var
doc: IHTMLDocument2;
win: IHTMLWindow2;
Olelanguage: OleVariant;
begin
Result := False;
if WebBrowser <> nil then
begin
try
doc := IHTMLDocument2(WebBrowser.Document);
win := doc.parentWindow;
if win <> nil then
begin
try
Olelanguage := language;
win.ExecScript(script, Olelanguage);
Result := True;
finally
win := nil;
end;
end;
finally
doc := nil;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://fundf10.eastmoney.com/jjjz_090001.html');
end;
procedure TForm1.Button2Click(Sender: TObject);
var
O: OleVariant;
begin
O := WebBrowser1.OleObject.Document.all.item('k', 0);
O.value := '260104';
O := WebBrowser1.OleObject.Document.all.item('a', 0);
O.value := '2008-1-1';
O := WebBrowser1.OleObject.Document.all.item('b', 0);
O.value := '2008-1-31';
ExecuteScript(WebBrowser1,'jisuan04();');
end;