如何能不弹出webbrowser访问网页时有时出现的脚本错误对话框? 
WebBrowser1.Silent :=True;这个方法不行,同样会弹出脚本错误对话框,

解决方案 »

  1.   

    我测试了、若WebBrowser1的属性Silent設定為True、就不会出「脚本错误对话框」了呀!
      

  2.   

    还有一种方法就是sink 浏览器控件的IOleCommandTarget接口的Exec方法
      

  3.   

    jiangsheng(蒋晟.MSMVP2004Jan) :
    要具体说出怎样实现才可以啊 cronuz(cronus) :
    可能你遇到的情况比较少
      

  4.   

    The WebBrowser control notifies its host of an unhandled script error through the IOleCommandTarget interface. The host can then retrieve the information about the error, display (or suppress) an error message to the user, and choose whether to run scripts on the page. When one of the script engines encounters an unhandled error, it forwards the error to the WebBrowser control, which then queries its container to see if the container has implemented IOleCommandTarget. If the container has implemented IOleCommandTarget, the WebBrowser control calls the IOleCommandTarget::Exec method with the command group ID of CGID_DocHostCommandHandler (which is defined in the Mshtmhst.h file) and a command ID of OLECMDID_SHOWSCRIPTERROR. If the host does not return S_OK, MSHTML displays the default "An error has occurred on this page" error message.The following code illustrates how to implement a handler for this command ID that retrieves the error information from the document object model. This code does not illustrate error handling.
    STDMETHODIMP CMyBrowser::Exec( const GUID* pguidCmdGroup, DWORD nCmdID,
          DWORD nCmdexecopt, VARIANTARG* pvaIn, VARIANTARG* pvaOut )
       {      HRESULT hr = S_OK;      if (pguidCmdGroup && IsEqualGUID(*pguidCmdGroup, CGID_DocHostCommandHandler))
          {
             
             switch (nCmdID) 
             {
             
             case OLECMDID_SHOWSCRIPTERROR:
             {
                IHTMLDocument2*             pDoc = NULL;
                IHTMLWindow2*               pWindow = NULL;
                IHTMLEventObj*              pEventObj = NULL;
                BSTR                        rgwszNames[5] = 
                                            { 
                                               SysAllocString(L"errorLine"),
                                               SysAllocString(L"errorCharacter"),
                                               SysAllocString(L"errorCode"),
                                               SysAllocString(L"errorMessage"),
                                               SysAllocString(L"errorUrl")
                                            };
                DISPID                      rgDispIDs[5];
                VARIANT                     rgvaEventInfo[5];
                DISPPARAMS                  params;
                BOOL                        fContinueRunningScripts = true;
                int                         i;            params.cArgs = 0;
                params.cNamedArgs = 0;            // Get the document that is currently being viewed.
                hr = pvaIn->punkVal->QueryInterface(IID_IHTMLDocument2, (void **) &pDoc);
                // Get document.parentWindow.
                hr = pDoc->get_parentWindow(&pWindow);
                pDoc->Release();
                // Get the window.event object.
                hr = pWindow->get_event(&pEventObj);
                // Get the error info from the window.event object.
                for (i = 0; i < 5; i++) 
                {  
                   // Get the property's dispID.
                   hr = pEventObj->GetIDsOfNames(IID_NULL, &rgwszNames[i], 1, 
                           LOCALE_SYSTEM_DEFAULT, &rgDispIDs[i]);
                   // Get the value of the property.
                   hr = pEventObj->Invoke(rgDispIDs[i], IID_NULL,
    LOCALE_SYSTEM_DEFAULT,
                           DISPATCH_PROPERTYGET, &params, &rgvaEventInfo[i],
    NULL, NULL);
                   SysFreeString(rgwszNames[i]);
                }            // At this point, you would normally alert the user with 
                // the information about the error, which is now contained
                // in rgvaEventInfo[]. Or, you could just exit silently.            (*pvaOut).vt = VT_BOOL;
                if (fContinueRunningScripts)
                {
                   // Continue running scripts on the page.
                   (*pvaOut).boolVal = VARIANT_TRUE;
                }
                else
                {
                   // Stop running scripts on the page.
                   (*pvaOut).boolVal = VARIANT_FALSE;
                } 
                break;
             }
             default:
                hr = OLECMDERR_E_NOTSUPPORTED;
                break;
             }
          }
          else
          {
             hr = OLECMDERR_E_UNKNOWNGROUP;
          }
          return (hr);
       }
      

  5.   

    <script>
    try
    {
    //访问代码
    }
    catch(e){}
    </script>
    就无错误提示了
      

  6.   

    //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;説明:楼主想必NI自己己解決了、不過試試看、
       此方法可屏蔽対話框的出現。