如何禁止脚本错误对话框?

horsehorse 2003-05-21 11:42:28
加精
请问在CHTMLView中,如何禁止/允许弹出脚本错误对话框?
...全文
284 点赞 收藏 6
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sl816 2003-06-06
CHtmlView::SetSilent(TRUE);
回复
Tue 2003-05-29
在IE设置的高级选项里关掉就可以了。
回复
horsehorse 2003-05-22
多谢多谢!
回复
蒋晟 2003-05-21
Knowledge Base

HOWTO: Handle Script Errors as a WebBrowser Control Host
PSS ID Number: 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.

.....
回复
horsehorse 2003-05-21
多谢!
不过还有没有简单点的方法?
回复
masterz 2003-05-21
give a try

IDocHostShowUI::ShowMessage
Return S_OK to disable WebBrowser Control messages. Any other return value, like S_FALSE or E_NOTIMPL, allows the WebBrowser Control to display with its message box.

One nice thing you can do with this method is customize the message box captions for your application so they don't read "Microsoft Internet Explorer." You can do this by comparing the caption string in lpstrCaption with the string resource Internet Explorer uses, which is stored in Shdoclc.dll. It is identified by the symbol IDS_MESSAGE_BOX_TITLE, whose value is 2213. The following code snippet shows how you might do this.

Hide Example

HRESULT CBrowserHost::ShowMessage(HWND hwnd,
LPOLESTR lpstrText,
LPOLESTR lpstrCaption,
DWORD dwType,
LPOLESTR lpstrHelpFile,
DWORD dwHelpContext,
LRESULT *plResult)
{
USES_CONVERSION;
TCHAR pBuffer[50];

// resource identifier for window caption "Microsoft Internet Explorer"
#define IDS_MESSAGE_BOX_TITLE 2213

// Load Shdoclc.dll and the IE message box title string
HINSTANCE hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL"));
LoadString(hinstSHDOCLC, IDS_MESSAGE_BOX_TITLE, pBuffer, 50);

// Compare the IE message box title string with lpstrCaption
// If they're the same, substitute your own Caption
if (_tcscmp(OLE2T(lpstrCaption), pBuffer) == 0)
lpstrCaption = L"Custom Caption";

// Create your own message box and display it
*plResult = MessageBox(OLE2T(lpstrText), OLE2T(lpstrCaption), dwType);

// Unload Shdoclc.dll and return
FreeLibrary(hinstSHDOCLC);
return S_OK;
}
回复
发动态
发帖子
HTML/XML
创建于2007-09-28

3053

社区成员

VC/MFC HTML/XML
申请成为版主
社区公告
暂无公告