About ways to use CDHtmlDialog to prevent scripting errors in MFC projects

Source: Internet
Author: User

When a Web page loaded with the WebBrowser control (CDHtmlDialog automatically creates the WebBrowser control) contains error JavaScript code, the control pops up the error message prompt dialog box by default. As with the user experience, such a hint is not what the developer wants, there are two solutions to this problem, one is to completely block out the error prompts, the other is to control the error of the prompts and log the error message can also control the error after the JavaScript continues to execute.

1, shielding error message Tips

? View Plain M_pbrowserapp->put_silent (VARIANT_TRUE)//Disable script error prompt

In the code for Cdhtmldialog::oninitdialog (), you first create the WebBrowser control, and then assign the control's browser object to m_pBrowserApp (this is done by CDHtmlDialog without having to handle it yourself). The official description of the WebBrowser put_silent function is to disable all dialog boxes, except that it does not affect the incoming dialog box required for SSL security authentication. In most cases, this will solve the problem. I remember a long time ago I encountered a situation is that although the call to put_silent but there are very few JS errors can not be blocked will still be displayed (in the Web page contains nested pages will be error can not be blocked, do not know whether there are other circumstances), Now can not find such a Web page, if the person who encountered this situation suggested to send me a URL let me also relive the sunny moment.

2, control the error prompts and record

This is much more complicated than the first method, and the short one is to customize the COleControlSite class and implement the IOleCommandTarget interface, IOleCommandTarget interface is the key to error control, When an error occurs, the EXEC function of this interface is triggered and the nCmdID parameter is assigned a value of Olecmdid_showscripterror so that the error message can be obtained.

?

1 2 3 4 5 6 7

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.