使用webbrowser作为浏览器,网页中使用window.alert("")弹出一个提示框,如果通过程序将该提示框关掉,或者使它不出现。

解决方案 »

  1.   

    把webbrowser的属性「Silent」設定為:true
      

  2.   

    那个silent属性是不出来错误提示的,对这个没有用。
      

  3.   

    我在网吧里,没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则传如该函数原有的参数原形,参数名字不必相同,数目相同就可以了
      

  4.   

    好象有点问题window:=(Browser.Document as IHTMLDocument2).parentWindow;
    改为
    window:=(Browser.Document as IHTMLDocument2).parentWindow as IHTMLWindow2;
      

  5.   

    //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;説明:此方法可屏蔽対話框的出現