I want to prevent IE from showing JS error dialogs, I read that it can be done by setting ScriptErrorsSuppressed = true.
Where exact开发者_StackOverflowly do I set it in IWebBrowser2?
Thanks
Simply use put_Silent method.
m_pWebBrowser->put_Silent(VARIANT_TRUE);
As mentioned earlier, use the put_Silent()
method to turn error reporting on or off.
For example, if using a CDHtmlDialog
, put this in your OnInitDialog()
:
m_pBrowserApp->put_Silent(VARIANT_TRUE);
and put it before the LoadFromResource()
call.
Be careful though as this will suppress a lot more messages than just JavaScript errors. (Think SSL certificate notifications.)
make change in both HKEY_CURRENT_USER
and HKEY_LOCAL_MACHINE
paths.
Software\\Microsoft\\Internet Explorer\\Main
RegSetValueEx (hKey, LPCSTR("Disable Script Debugger"), 0, REG_SZ, (BYTE*) "yes", 3);
RegSetValueEx (hKey, LPCSTR("DisableScriptDebuggerIE"), 0, REG_SZ, (BYTE*) "yes", 3);
The docs you are reading refer to what you can do if you embed an IE HTML rendering pane in your own application. They allow you to alter the behavior of that pane.
If you have done that, then you can use COM to QueryInterface an IWebBrowser2 interface from the component.
See more here:
http://support.microsoft.com/kb/196340
And here's how you handle errors:
http://support.microsoft.com/kb/261003
I suspect that that's not what you are trying to do, and that you are just making a web-app. In that case, you need to
- Fix your JS errors
- Put all of your JS code in try/catch blocks. Then you won't get JS dialogs, but you need to handle the error yourself.
The quick and easy way would be to use a global state to solve a local problem and modify the registry as described here (although Raymond would disapprove of doing so). This basically deactivates script errors entirely for the currently logged in user.
Summary:
- Registry Key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
- Value Name: Disable Script Debugger
- Data Type:
REG_SZ
(String Value) - Value Data: yes
The more complex solution would be implementing IOleCommandTarget, as already pointed out by Lou.
精彩评论