Interface usesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Olectrls, SHDocVw, ActiveX; typeIdochostshowui=Interface(IUnknown) ['{C4D244B0-D43E-11CF-893B-00AA00BDCE1A}'] functionShowMessage (hwnd:thandle; lpstrtext:polestr; lpstrcaption:polestr;dwtype:longint; lpstrhelpfile:polestr; Dwhelpcontext:longint;varPlresult:lresult): HRESULT;stdcall; functionShowHelp (hwnd:thandle; pszhelpfile:polestr; ucommand:integer;dwdata:longint; ptmouse:tpoint;varPdispatchobjecthit:idispatch): HRESULT;stdcall; End; Twebbrowser=class(Shdocvw.twebbrowser,idochostshowui)protected functionShowMessage (hwnd:thandle; lpstrtext:polestr; lpstrcaption:polestr;dwtype:longint; lpstrhelpfile:polestr; Dwhelpcontext:longint;varPlresult:lresult): HRESULT;stdcall; functionShowHelp (hwnd:thandle; pszhelpfile:polestr; ucommand:integer;dwdata:longint; ptmouse:tpoint;varPdispatchobjecthit:idispatch): HRESULT;stdcall; End; typeTForm1=class(tform) Webbrowser1:twebbrowser; procedureformcreate (Sender:tobject); Private {Private Declarations} Public {Public Declarations} End; varForm1:tform1; Implementation {$R *.DFM} {Twebbrowser} functiontwebbrowser.showhelp (hwnd:thandle; pszhelpfile:polestr; Ucommand, Dwdata:integer; Ptmouse:tpoint ;varpdispatchobjecthit:idispatch): HRESULT; beginResult:=S_FALSE; End; functiontwebbrowser.showmessage (hwnd:thandle; lpstrtext, lpstrcaption:polestr; dwtype:integer; lpstrhelpfile:polestr; Dwhelpcontext:integer; varplresult:lresult): HRESULT; begin//plresult:= MessageBoxW (Hwnd,pwchar (Lpstrtext),'Title', -);//The alert Result is blocked here:=S_OK; End; proceduretform1.formcreate (Sender:tobject); beginWebBrowser1.Navigate ('e:/alert.htm'); End; End.
The method is to implement the Idochostshowui interface, overriding the method of ejecting the message.
Delphi WebBrowser Intercept Web Alert dialog message (GO)