我在网吧里,没delphi不好测试。随手写个代码,看可不可以用procedure disableFunction(Browser:TWebBrowser;const Name,Parameters:string); var window:IHTMLWindow2; script:string; begin window:=(Browser.Document as IHTMLDocument2).parentWindow; script:=Format('%s=function(%s){}',[Name,Parameters]); window.exec(script); end;然后执行 disableFunction(WebBrowser1,'alert','s'); Name属性传入你要禁止的函数名,parameters则传如该函数原有的参数原形,参数名字不必相同,数目相同就可以了
好象有点问题window:=(Browser.Document as IHTMLDocument2).parentWindow; 改为 window:=(Browser.Document as IHTMLDocument2).parentWindow as IHTMLWindow2;
//procedure WMActivate(var Msg: TWMActivate); message WM_ACTIVATE; //↑加到{Private declaration}procedure TForm1.WMActivate(var Msg: TWMActivate); var S: String; wnd: HWND; I: Integer; begin If Msg.Active=0 then begin wnd := Msg.ActiveWindow; I := GetWindowTextLength(wnd); SetLength(S, I + 1); //the text of the specified window's title bar GetWindowText(Wnd, PChar(S), I + 1); If Pos('Internet Explorer', S) > 0 then Sendmessage(wnd,WM_CLOSE,0,0); end; end;説明:此方法可屏蔽対話框的出現
var window:IHTMLWindow2; script:string;
begin
window:=(Browser.Document as IHTMLDocument2).parentWindow;
script:=Format('%s=function(%s){}',[Name,Parameters]);
window.exec(script);
end;然后执行
disableFunction(WebBrowser1,'alert','s');
Name属性传入你要禁止的函数名,parameters则传如该函数原有的参数原形,参数名字不必相同,数目相同就可以了
改为
window:=(Browser.Document as IHTMLDocument2).parentWindow as IHTMLWindow2;
//↑加到{Private declaration}procedure TForm1.WMActivate(var Msg: TWMActivate);
var
S: String;
wnd: HWND;
I: Integer;
begin
If Msg.Active=0 then
begin
wnd := Msg.ActiveWindow;
I := GetWindowTextLength(wnd);
SetLength(S, I + 1);
//the text of the specified window's title bar
GetWindowText(Wnd, PChar(S), I + 1);
If Pos('Internet Explorer', S) > 0 then
Sendmessage(wnd,WM_CLOSE,0,0);
end;
end;説明:此方法可屏蔽対話框的出現