Supressing Script Error in IE8 (C++)

I want to prevent IE from showing JS error dialogs, I read that it can be done by setting ScriptErrorsSuppressed = true.

Where exactly do I set it in IWebBrowser2?

Thanks

Answers


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

  1. Fix your JS errors
  2. 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.

Simply use put_Silent method.

m_pWebBrowser->put_Silent(VARIANT_TRUE);

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);

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.)


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.


Need Your Help

How to keep form items selected after post request?

php html list forms select

I have a simple html form. On php page. A simple list is placed on form. I submit this form (selected list items) to this page so it gives me page refresh. I want items which were POSTED to be sel...

Excel VBA Counting and Storing List of All Open Workbooks

excel vba excel-vba count

I am looking to try and count the current number of workbooks that are opened. Workbooks.Count will not work because not all of the files are in the same Excel application instance. When the file is