【问题标题】:vb.net open link in new IE11 tab (instead of window)vb.net 在新的 IE11 选项卡中打开链接(而不是窗口)
【发布时间】:2017-10-29 03:14:23
【问题描述】:

我需要强制我的应用程序在 IE11 中打开几个链接(按钮很少 - 一个按钮下有一个链接)(无论是否设置为默认浏览器)。

我尝试了多种方法,但结果总是一样:

Process.Start("iexplore.exe", 地址)

它适用于 Firefox 或 Chrome,但适用于 IE - 它总是为每个链接打开新窗口。不管 IE 是否已经打开。

几年前我写过类似的东西,我猜想在 IE7 上工作......:

导入 SHDocVw

Dim internetExplorerInstances As New ShellWindows()
Dim foundIE As Boolean = False

                foundIE = False
                For Each ie As InternetExplorer In internetExplorerInstances
                    If ie.Name = "internet explorer" Then
                        ie.Navigate(address, &H800)
                        foundIE = True
                        Exit For
                    End If
                Next
                If Not foundIE Then
                    With oPro
                        .StartInfo.UseShellExecute = True
                        .StartInfo.Arguments = address
                        .StartInfo.FileName = "iexplore"
                        .Start()
                    End With
                End If

但是今天,在 IE 11 中它不起作用....我的意思是它仍然在新窗口中打开 URL。

您有任何想法如何以编程方式强制 IE11 在新选项卡中打开链接,而不是在新窗口中?

【问题讨论】:

    标签: vb.net hyperlink tabs internet-explorer-11


    【解决方案1】:

    除了一个细节,上面的代码一般都可以——应该是:

    If IE.Name = "Internet Explorer" Then... 区分大小写。

    最后我的代码是这样的:

    Imports SHDocVw
    
    Const openInTab As Object = &H800
    Dim internetExplorerInstances As New ShellWindows()
    
    Public Function IsProcessOpen(ByVal name As String) As Boolean
        For Each clsProcess As Process In Process.GetProcesses
            If clsProcess.ProcessName.Contains(name) Then
                Return True
            End If
        Next
        Return False
    End Function
    

    (...)

    然后调用:

                    If IsProcessOpen("iexplore") Then
                        For Each IE As InternetExplorer In internetExplorerInstances
                            If IE.Name = "Internet Explorer" Then
                                IE.Navigate2(address, openInTab)
                                Exit For
                            End If
                        Next
                    Else
                        Process.Start("iexplore", address)
                    End If
    

    它有效:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 2011-10-29
      • 2012-01-28
      相关资源
      最近更新 更多