【问题标题】:Changing webbrowser default更改网络浏览器默认值
【发布时间】:2014-08-12 14:35:51
【问题描述】:

我面临的另一个问题与网络浏览器默认使用的 IE 有关。有些计算机无法正常运行网站并面临错误,所以我想将浏览器更改为适用于所有人的浏览器。我尝试了 shell 等,但我希望网站在网络浏览器上打开。此外,网络浏览器没有任何按钮文本框,默认情况下我想要该页面。 有人可以帮忙吗?

【问题讨论】:

  • 重复使用 Chrome、WebKit 或 Gecko 作为浏览器控件:stackoverflow.com/q/790542/1070452
  • 他们没有给出真正解决问题的有效答案。
  • 这一切都取决于您的用户的安装(WebBrowser控件使用已安装的IE版本)。您应该为您的应用程序设置一些先决条件,例如“IE = X 的最低版本”。还要确保 WebBrowser 控件不使用旧的 IE 兼容模式(如果安装了 IE8,它在某些情况下会使用 IE7 兼容性)。
  • 实际上尝试使用它的人说他在Windows 7上安装了IE 11并且得到了无法显示的网页,其中包含一半的url。

标签: vb.net browser webbrowser-control


【解决方案1】:

创建一个名为 Form1 的表单或直接命名,删除所有代码并粘贴到下面,现在您将使用当前安装的 IE 浏览。

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CreateBrowserKey()

'Below code adds a custom useragent, adding a custom useragent does not change the actual engine...thats why we need to do all this coding.
WebBrowser1.Navigate("http://www.whatsmybrowser.org", "_top", Nothing, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36")

'This goes to the website using default user agent.
   'WebBrowser1.Navigate("http://www.whatsmybrowser.org")
End Sub

Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
        RemoveBrowerKey()
    End Sub

    Private Const BrowserKeyPath As String = "\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION"
    Private Sub CreateBrowserKey(Optional ByVal IgnoreIDocDirective As Boolean = False)
        Dim basekey As String = Microsoft.Win32.Registry.CurrentUser.ToString
        Dim value As Int32
        Dim thisAppsName As String = My.Application.Info.AssemblyName & ".exe"
        ' Value reference: http://msdn.microsoft.com/en-us/library/ee330730%28v=VS.85%29.aspx
        ' IDOC Reference:  http://msdn.microsoft.com/en-us/library/ms535242%28v=vs.85%29.aspx
        Select Case (New WebBrowser).Version.Major
            Case 8
                If IgnoreIDocDirective Then
                    value = 8888
                Else
                    value = 8000
                End If
            Case 9
                If IgnoreIDocDirective Then
                    value = 9999
                Else
                    value = 9000
                End If
            Case 10
                If IgnoreIDocDirective Then
                    value = 10001
                Else
                    value = 10000
                End If

            Case 11
                If IgnoreIDocDirective Then
                    value = 11001
                Else
                    value = 11000
                End If
            Case Else
                Exit Sub
        End Select
        Microsoft.Win32.Registry.SetValue(Microsoft.Win32.Registry.CurrentUser.ToString & BrowserKeyPath, _
                                          Process.GetCurrentProcess.ProcessName & ".exe", _
                                          value, _
                                          Microsoft.Win32.RegistryValueKind.DWord)
    End Sub

    Private Sub RemoveBrowerKey()
        Dim key As Microsoft.Win32.RegistryKey
        key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(BrowserKeyPath.Substring(1), True)
        key.DeleteValue(Process.GetCurrentProcess.ProcessName & ".exe", False)
    End Sub

End Class

【讨论】:

  • 为什么使用 IgnoreIDocDirective 参数?
  • 这行不通,因为您已经在此行声明了浏览器用户代理:WebBrowser1.Navigate("http://www.whatsmybrowser.org", "_top", Nothing, "User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36") 如果您删除此行,然后手动导航到 whatsmybrowser,您将获得 IE,而不是 Chrome。 不错的尝试:P
【解决方案2】:

【讨论】:

  • 现在我将使用 firefox (geckoFX) 并关注 MSDN 上的问题。谢谢。 :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 2017-09-25
  • 1970-01-01
  • 2010-12-12
  • 2011-01-12
相关资源
最近更新 更多