Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

Under the web browser Control in wpf .Net you have no direct possibility to disable the error display by script errors

 

Although there is the property webBrowser.Silent = false under Windows.Forms, you can not find it in WPF.Webbrowser controls.

Unfortunately, you have to add a small static class in order to disable the browser errors.

 

Then, before opening the web page, you have to switch the browser to javascript error suppression as here, where ctlBrowser is in this case the embedded browser.

clsWebbrowser_Errors.SuppressscriptErrors(ctlBrowser, true);

 

 

Additional static class: clsWebbrowser_Errors.cs

 

 

Turn off script errors before calling a web page in WPF Webbrowser Control

//--< loadHTML String to Browser >--

clsWebbrowser_Errors.SuppressscriptErrors(ctlBrowser, true);

ctlBrowser.NavigateToString(sTest);

//--</ loadHTML String to Browser >--

 

 

Separate static class to disable the script errors in the WPF Webbrowser Control

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

 

using System.Reflection;        //*Fieldinfo

using System.Windows.Controls;  //*Webbrowser Control

 

namespace Fritzbox_Tools

{

    public static class clsWebbrowser_Errors

    {

        //*set wpf webbrowser Control to silent

        //*code source: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f686de1-8884-4a8d-8ec5-ae4eff8ce6db

 

        public static void SuppressscriptErrors(this WebBrowser webBrowser, bool hide)

        {

            FieldInfo fiComWebBrowser = typeof(WebBrowser).GetField("_axIWebBrowser2", BindingFlags.Instance | BindingFlags.NonPublic);

            if (fiComWebBrowser == null)

                return;

            object objComWebBrowser = fiComWebBrowser.GetValue(webBrowser);

            if (objComWebBrowser == null)

                return;

 

            objComWebBrowser.GetType().InvokeMember("Silent", BindingFlags.SetProperty, null, objComWebBrowser, new object[] { hide });

        }

    }

}

 

 

The code source is: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4f686de1-8884-4a8d-8ec5-ae4eff8ce6db

 

Mobile
»
WPF Datagrid: Set Color of Row when it has no Focus
»
WPF Datagrid: Change the Color of Selected Row
»
WPF: Change Selected Row Color in DataGrid
»
WPF: Read SelectedItem from DataGrid with Dynamic As Anonymous Type
»
WPF: Elements too wide, edge Cut off
»
Solved: System.InvalidCastException HResult 0x80004002 in Select DataGrid
»
WPF: Combobox Selected Value
»
WPF Datagrid: Column is not displayed
»
WPF: Show video in preview
»
WPF Webbrowser: Suppress Java Errors or Set WebBrowser to Silent

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de