在ie8和ie6内核下都存在此问题:ie8的webcontrol禁止脚本错误框弹出功能,对其他网页有用,但唯独对这个不管用,还是会跳出脚本错误的框,并问是否继续。一个在线播放电影的网站,应该是迅雷旗下的
http://gvodb.com/play/2009/03/44205.html?gvod=1#playlabel它本身有一些脚本错误,也跳框,我为屏蔽广告,把pee.cn和unionli.com加到内容过滤列表,结果就出现脚本错误提示框。但我对sohu.com进行广告过滤,不会跳框,而且其他网页脚本错误了也不跳框。唯独那个电影网站跳,搞了2天也没搞定它。我的浏览器这有关此功能的代码见下:浏览器源码:http://myie9.googlecode.com/files/openbrowser-1.0.0-beta-src.zip加上DLCTL_SILENT也不管用:
BOOL CMyIE9View::OnAmbientProperty(COleControlSite* pSite, DISPID dispid, VARIANT* pvar) 
{
try{

// TODO: Add your specialized code here and/or call the base class
if (dispid == DISPID_AMBIENT_DLCONTROL)
{
pvar->vt = VT_I4;
pvar->lVal = m_dwProperty; 
if (pmf->m_bDisDownActivex)
pvar->lVal |= DLCTL_NO_DLACTIVEXCTLS | DLCTL_SILENT; return TRUE;
}
return CFixedHtmlView::OnAmbientProperty(pSite, dispid, pvar);

}catch(...){ASSERT(false); return FALSE;}
}
 //silent g_bSilent = GetProfileInt("Settings", "Silent", TRUE); if (g_bSilent != (_RegGetString(HKEY_CURRENT_USER,   "Software\\Microsoft\\Internet Explorer\\Main",  "Disable Script Debugger") == "yes" ? TRUE : FALSE)) {  if (g_bSilent)   _RegSetString(HKEY_CURRENT_USER,     "Software\\Microsoft\\Internet Explorer\\Main",    "Disable Script Debugger",    "yes");  else   _RegSetString(HKEY_CURRENT_USER,     "Software\\Microsoft\\Internet Explorer\\Main",    "Disable Script Debugger",    "no"); } /**
http://support.microsoft.com/default.aspx?scid=kb;en-us;261003
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.
NOTE: This method will not be invoked if the user has cleared the Disable Script Debugging check box in the Advanced tab under Internet Options. 
*/
STDMETHODIMP CCustomControlSite::XOleCommandTarget::Exec(
   /* [unique][in] */ const GUID __RPC_FAR *pguidCmdGroup,
   /* [in] */ DWORD nCmdID,
   /* [in] */ DWORD nCmdexecopt,
   /* [unique][in] */ VARIANT __RPC_FAR *pvaIn,
   /* [unique][out][in] */ VARIANT __RPC_FAR *pvaOut
   )
{
 
 HRESULT hr = S_OK;
 BOOL bActiveX = FALSE;
 try{
  if (pguidCmdGroup && IsEqualGUID(*pguidCmdGroup, CGID_DocHostCommandHandler))
  {
   if((nCmdID == 40 || nCmdID == 41) && pmf!=NULL && g_bSilent)// OLECMDID_SHOWSCRIPTERROR = 40, OLECMDID_SHOWMESSAGE = 41,
   {
    if(nCmdID == 41)
    {
     IHTMLDocument2*             pDoc = NULL;
     IHTMLWindow2*               pWindow = NULL;
     IHTMLEventObj*              pEventObj = NULL;
     BSTR                        rgwszName = SysAllocString(L"messageText");
     DISPID                      rgDispID;
     VARIANT                     rgvaEventInfo;
     DISPPARAMS                  params;
     
     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.
     // Get the property's dispID.
     hr = pEventObj->GetIDsOfNames(IID_NULL, &rgwszName, 1, 
      LOCALE_SYSTEM_DEFAULT, &rgDispID);
     // Get the value of the property.
     hr = pEventObj->Invoke(rgDispID, IID_NULL,LOCALE_SYSTEM_DEFAULT,
      DISPATCH_PROPERTYGET, &params, &rgvaEventInfo,NULL, NULL);
     SysFreeString(rgwszName);
     pWindow->Release();
     pEventObj->Release();
     if(wcsstr(rgvaEventInfo.bstrVal, L" ActiveX ")!=NULL)
      bActiveX = TRUE;
     SysFreeString(rgvaEventInfo.bstrVal);
    }
    
    (*pvaOut).vt = VT_BOOL;
    // Continue running scripts on the page.
    (*pvaOut).boolVal = VARIANT_TRUE;
    
    if(nCmdID == 40)
     pmf->SetMessageText("Script Error!");
    else if(bActiveX)
     pmf->SetMessageText("ActiveX Denied!");    
    else
    {
     (*pvaOut).boolVal = VARIANT_FALSE;
     return OLECMDERR_E_NOTSUPPORTED;
    }    return hr;
    
   }
  }
 }catch(...){} return OLECMDERR_E_NOTSUPPORTED;
}

解决方案 »

  1.   

    补充一下,ie内核的浏览器,如傲游和myie9都存在此问题。
      

  2.   

    To LZ:根据我写的经验, OnAmbientProperty 可以设置脚本静默 .(但是有副作用,不过似乎你没遇到)你也可以对特定网站的脚本静默, 你这样干:bool _bSlient ;OnAmbientProperty
    {
        if( _bSlient )
        {
        }
        else
        {
        }
    }BeforeNavigate2()
    {
        if( url == yourWantHost )
        {
             _bSlient = true ;
             //Tell WebBrowser your ambient property changed
             pClientCtrl->OnAmbientPropertyChange( DISPID_AMBIENT_DLCONTROL);
        }
    }