javascript - How to prevent script error in C# webbrowser? - Stack Overflow

admin2025-04-18  0

I am getting script error in loading some web sites.

Please help me how to prevent script error in C# WebBrowser.

This is my code:

try
{
    webBrowser1.Navigate(textBox1.Text);
    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
    {
        Application.DoEvents();
    }

    MessageBox.Show("Loaded");
}
catch(Exception)
{
    MessageBox.Show("failed");
}

I am getting script error in loading some web sites.

Please help me how to prevent script error in C# WebBrowser.

This is my code:

try
{
    webBrowser1.Navigate(textBox1.Text);
    while (webBrowser1.ReadyState != WebBrowserReadyState.Complete)
    {
        Application.DoEvents();
    }

    MessageBox.Show("Loaded");
}
catch(Exception)
{
    MessageBox.Show("failed");
}
Share edited Aug 8, 2012 at 17:03 Mat 207k41 gold badges402 silver badges418 bronze badges asked Aug 8, 2012 at 16:40 user1576034user1576034 852 gold badges5 silver badges13 bronze badges 5
  • 4 I don't suppose you're going to share the script error message, are you? – LittleBobbyTables - Au Revoir Commented Aug 8, 2012 at 16:42
  • 1 This is kinda like hiring a plumber and not telling him what was leaking :p – John Humphreys Commented Aug 8, 2012 at 16:44
  • 1 @LittleBobbyTables Your name is amazing. – Wesley Commented Aug 8, 2012 at 16:45
  • @Wesley:- Wanted to +2 your ment... – perilbrain Commented Aug 8, 2012 at 16:49
  • Script error is: An error has occured in the script on this page Do you want to continue running script on this page? – user1576034 Commented Aug 8, 2012 at 16:51
Add a ment  | 

5 Answers 5

Reset to default 4

Write this in Your Code

 webBrowser1.ScriptErrorsSuppressed = true;

To disable the script error pop up, you need to go to (in Internet Explorer) Tools->Internet Options, there go to the Advanced tab, and in Browsing select Disable Script Debugging (Other), but, the problem may be related to the fact that every site loaded in the WebBrowser control is rendered in IE7 patibility mode, to solve this the only thing you can do is a registry hack like this: WebBrowser control to use IE9

change your registry to 2af8 which is IE 11 for devenv.exe software/Microsoft/internet explorer/main/featurecontrol/feature_Browser_emulation

If your working with a GUI (like in Visual Studio) just go to the Webbrowser Properties and set "ScriptErrorsSuppressed" = true

It is easy to see how this error has been eliminated. But Visual Studio uses Internet Explorer and another Web Browser coding is hard. If you look at the versions, the last Visual Studio one uses IE 11 for WebBrowser tool.

The C++ GUI is remended for one of each encoding: https://msdn.microsoft./en-us/library/60k1461a.aspx

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744932165a275222.html

最新回复(0)