//非框架结构的网页可以这样
uses MSHTML;
procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
vDocument: IHTMLDocument2;
begin
vDocument := TWebBrowser(Sender).Document as IHTMLDocument2;
vDocument.parentWindow.execScript('function alert(str){return;}', 'javaScript');
//框架的就用IHTMLFrameBase2.contentWindow.execScript
vDocument.parentWindow.execScript('function confirm(str){return str == "Zswang";}', 'javaScript');
end;