【问题标题】:Why doesn't webbrowser work in Visual Studio 2019? [duplicate]为什么 webbrowser 在 Visual Studio 2019 中不起作用? [复制]
【发布时间】:2019-12-16 23:05:54
【问题描述】:

我在winforms 上使用webbrowser 编写了一个简单的应用程序。页面已加载,但有一些缺陷,页面显示,但在 Internet Explorer 11 中并非如此。大多数 java 脚本都不起作用(可能是全部)。有些网站会警告我的浏览器已过时,但我读到网络浏览器使用 Windows 中的内置 Internet Explorer。那么,为什么在 Internet Explorer 中一切正常,而在网络浏览器中几乎一切都不起作用? 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/");
        }
    }
}

【问题讨论】:

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


【解决方案1】:

查看 Windows 社区工具包,它公开了适用于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-03
    • 1970-01-01
    • 2023-03-06
    • 2021-06-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多