4

What happens when I close my app, which uses webbrowser. The following url uses flash player.

alt text

Everything works fine. This error shows on app close. How do I ignore it?

Fantastic Mr Fox
  • 32,495
  • 27
  • 95
  • 175
John black
  • 527
  • 2
  • 6
  • 9
  • 1
    I hope you don't use the same principle when you see errors/warnings from your compiler. "It works fine, so how do I hide the errors?" is never a good question to be asking. – Cody Gray - on strike Jan 11 '11 at 08:50
  • IE nor FF nor Chrome shows such errors. So why should I take attention at some activex control?! – John black Jan 11 '11 at 08:57

5 Answers5

5

I know it's too late, but I feel I have a smart answer for this issue.

Use this, it's working for me on a fly. :)

webBrowser.ScriptErrorsSuppressed = true;

If it's not working, we can use different methods like showing a confirmation box (Ex: This windows want to close do you want to continue Yes/ No)

[DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
    static extern IntPtr FindWindowByCaption(IntPtr ZeroOnly, string lpWindowName);

[DllImport("user32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

 private void TimerPopUp_Tick(object sender, EventArgs e)
        {
            IntPtr hWnd1 = FindWindowByCaption(IntPtr.Zero, "Web Browser");

            if (hWnd1 != IntPtr.Zero && SetForegroundWindow(hWnd1))
            {
                SendKeys.Send("{Enter}");
            }

        }

If there are any errors, see this link.

Community
  • 1
  • 1
2

You can disable javascrip errors by setting ScriptErrorsSuppressed property of WebBrowser control to true. It may not work sometimes though. If it does not work, check http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/46a32b08-3834-4a13-8170-e0eba2498284 and http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/07df5263-613c-4780-89a2-67ebf2a1e670

imaximchuk
  • 748
  • 5
  • 13
1

In Visual Studio 2015, there is an option that can enable or disable the popups.

In web browser propertiesScript Errors Suppressed, then set it to True to disable the popups.

thewaywewere
  • 8,128
  • 11
  • 41
  • 46
0

First you need to know that the webbrowser control is using IE7 as its base (i.e. the older version of Internet Explorer ) so the scripts which you are running now are compatible with the modern age browsers and thus the error. First of all, if you'll put:

<meta http-equiv="X-UA-Compatible" content="IE=edge"/>

inside your section of the page, it will render with the IE version installed on the machine instead of the default IE 7

Hope this Helps!

MICHAEL PRABHU
  • 419
  • 5
  • 11
0

You should make the WebBrowser Control COM Visible and give it the proper permissions:

#region Using Statements:



using System;
using System.Windows.Forms;
using System.Security.Permissions;



#endregion



[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{



public Form1()
{

InitializeComponent();

// WebBrowser Configuration:
webBrowser1.ObjectForScripting = this;
webBrowser1.AllowWebBrowserDrop = false;
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.WebBrowserShortcutsEnabled = false;
webBrowser1.IsWebBrowserContextMenuEnabled = false;

}




private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.google.com/");
}


}

or:

#region Using Statements:



using System;
using System.Windows.Forms;
using System.Security.Permissions;



#endregion



[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public partial class Form1 : Form
{



public Form1()
{

InitializeComponent();

// WebBrowser Configuration:
webBrowser1.ObjectForScripting = new ObjectForScripting();
webBrowser1.AllowWebBrowserDrop = false;
webBrowser1.ScriptErrorsSuppressed = true;
webBrowser1.WebBrowserShortcutsEnabled = false;
webBrowser1.IsWebBrowserContextMenuEnabled = false;

}




private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://www.google.com/");
}


[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class ObjectForScripting
{

// User Code to handle events..

}


}

Note: This may not run correctly in debug mode.

Also, if you need the Registry Key set for local App Compatibility, it also wont run in debug mode.

IsWOW64 = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";



IsNotWOW64 = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION";
Rusty Nail
  • 2,692
  • 3
  • 34
  • 55