如何在 IE WebBrowser 控件中禁用 javascript 错误调试
How to disable javascript error debugging in IE WebBrowser Control
应用程序正在使用 IE WebBrwoser 控件。但是有时会出现 javascript 错误对话框,为了解决这个 put_silent 属性 在 WebBrowser 元素上使用,但是禁用所有 dialogs.So 有没有办法禁用 Javascript WebBrowser控件调试错误?
在您的控件上单击鼠标右键,然后单击“检查元素”。如果您没有禁用 IE 菜单,它应该在右侧或底部打开 Developer window。 Select 选项卡 "Debug",单击六边形并选中 "Don't stop on exception" 或 "Stop on unhandled exceptions"。我相信这是浏览器的全局设置,所以你也许可以只从 IE 中进行设置。
更新 1
首先实施 IDocHostUIHandler 并包装外部处理程序调用。它在 Mshtmhst.h 中声明,因此您可能必须包含它。不要忘记 IUnknown 成员,也必须进行包装。 ATL 向导可用于实现接口,但无论如何你必须准确理解你所做的:
class MyDocHostUIHandler: public IDocHostUIHandler
{
public:
IDocHostUIHandler* externalHandler;
HRESULT EnableModeless( BOOL fEnable)
{
return externalHandler->EnableModeless(fEnable);
}
HRESULT FilterDataObject(IDataObject* pDO, IDataObject** ppDORet)
{
return externalHandler->FilterDataObject(pDO, ppDORet)ș
}
.... Wrap all the functions from External Handler like above
};
创建您的 class 实例:
MyDocHostUIHandler* myHandler = new MyDocHostUIHandler();
然后在你的代码中调用就像在MSDN中指定的那样。
首先你得到 MSHTML 对象
CComPtr<IHTMLDocument2> m_spDocument;
hr = m_WebBrowser->get_Document(&m_spDocument);// Get the MSHTML object
然后你得到现有的默认处理程序
ComPtr<IOleObject> spOleObject;
hr = m_spDocument.As(&spOleObject);
ComPtr<IOleClientSite> spClientSite;//<--this will be the default handler
hr = spOleObject->GetClientSite(&spClientSite);
将现有的处理程序保存到您的 class,这样您就可以包装它的函数
//see myHandler is the instance of interface you implemented in first step
myHandler->externalHandler = spClientSite;
获取自定义文档:
ComPtr<ICustomDoc> spCustomDoc;
hr = m_spDocument.As(&spCustomDoc);//m_spDocument it is the pointer to your MSHTML
现在从 HSMTML 替换处理程序:
//myHandler is the instance of class you implemented above
spCustomDoc->SetUIHandler(myHandler);
在这一步之后,MSHTML 应该不会注意到任何东西,但是您将能够在 MyDocHostUIHandler 中添加断点class 并查看您的 MSHTML 调用了哪个函数以及何时调用。
应用程序正在使用 IE WebBrwoser 控件。但是有时会出现 javascript 错误对话框,为了解决这个 put_silent 属性 在 WebBrowser 元素上使用,但是禁用所有 dialogs.So 有没有办法禁用 Javascript WebBrowser控件调试错误?
在您的控件上单击鼠标右键,然后单击“检查元素”。如果您没有禁用 IE 菜单,它应该在右侧或底部打开 Developer window。 Select 选项卡 "Debug",单击六边形并选中 "Don't stop on exception" 或 "Stop on unhandled exceptions"。我相信这是浏览器的全局设置,所以你也许可以只从 IE 中进行设置。
更新 1 首先实施 IDocHostUIHandler 并包装外部处理程序调用。它在 Mshtmhst.h 中声明,因此您可能必须包含它。不要忘记 IUnknown 成员,也必须进行包装。 ATL 向导可用于实现接口,但无论如何你必须准确理解你所做的:
class MyDocHostUIHandler: public IDocHostUIHandler
{
public:
IDocHostUIHandler* externalHandler;
HRESULT EnableModeless( BOOL fEnable)
{
return externalHandler->EnableModeless(fEnable);
}
HRESULT FilterDataObject(IDataObject* pDO, IDataObject** ppDORet)
{
return externalHandler->FilterDataObject(pDO, ppDORet)ș
}
.... Wrap all the functions from External Handler like above
};
创建您的 class 实例:
MyDocHostUIHandler* myHandler = new MyDocHostUIHandler();
然后在你的代码中调用就像在MSDN中指定的那样。 首先你得到 MSHTML 对象
CComPtr<IHTMLDocument2> m_spDocument;
hr = m_WebBrowser->get_Document(&m_spDocument);// Get the MSHTML object
然后你得到现有的默认处理程序
ComPtr<IOleObject> spOleObject;
hr = m_spDocument.As(&spOleObject);
ComPtr<IOleClientSite> spClientSite;//<--this will be the default handler
hr = spOleObject->GetClientSite(&spClientSite);
将现有的处理程序保存到您的 class,这样您就可以包装它的函数
//see myHandler is the instance of interface you implemented in first step
myHandler->externalHandler = spClientSite;
获取自定义文档:
ComPtr<ICustomDoc> spCustomDoc;
hr = m_spDocument.As(&spCustomDoc);//m_spDocument it is the pointer to your MSHTML
现在从 HSMTML 替换处理程序:
//myHandler is the instance of class you implemented above
spCustomDoc->SetUIHandler(myHandler);
在这一步之后,MSHTML 应该不会注意到任何东西,但是您将能够在 MyDocHostUIHandler 中添加断点class 并查看您的 MSHTML 调用了哪个函数以及何时调用。