为什么Webbrowser在Visual Studio 2019中不起作用?

时间:2019-08-09 08:20:45

标签: c# winforms internet-explorer webbrowser-control

我在winforms上使用webbrowser编写了一个简单的应用程序。页面已加载,但存在一些缺陷,但显示了页面,但在Internet Explorer 11中却无法显示页面。大多数Java脚本无法正常运行(可能无法全部运行)。一些网站警告我的浏览器已过期,但我阅读到该网络浏览器使用Windows中内置的Internet Explorer。那么,为什么所有内容都不能在Internet Explorer中工作,而几乎所有内容都不能在Web浏览器中工作? IDE版本:Visual Studio 2019。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true;
            webBrowser1.Url = new Uri("https://stackoverflow.com/");
        }
    }
}

1 个答案:

答案 0 :(得分:0)

看看Windows Community Toolkit,它为Windows 10提供了Edge浏览器。 https://github.com/windows-toolkit/WindowsCommunityToolkit

https://docs.microsoft.com/en-us/windows/communitytoolkit/controls/wpf-winforms/webview

如果必须使用默认的Web控件,则可以取消该警告,因为“ ScriptErrorsSupressed”通常无法完全正常工作。检查答案下方发布的解决方案。 Disable JavaScript error in WebBrowser control

在上述情况下也可能需要这样做,这将注册您的应用程序并强制其使用IE11。 Use latest version of Internet Explorer in the webbrowser control