简体   繁体   English

vb.net在新的IE11选项卡中打开链接(而不是窗口)

[英]vb.net open link in new IE11 tab (instead of window)

I need to force my application to open few links (there are few buttons - one link under one button) in IE11 (regardless if it's set as default browser or not). 我需要强制我的应用程序在IE11中打开几个链接(有几个按钮-一个按钮下有一个链接)(无论是否将其设置为默认浏览器)。

I tried multiple ways, but the result is always the same like with: 我尝试了多种方法,但结果始终与以下相同:

Process.Start("iexplore.exe", address) Process.Start(“ iexplore.exe”,地址)

It works perfectly for Firefox, or Chrome, but for IE - it always opens new window for each link. 它非常适合Firefox或Chrome,但适用于IE-始终为每个链接打开新窗口。 Regardless IE is already opened or not. 无论IE是否已打开。

Few years ago I wrote similar thing which worked with IE7 I guess...: 几年前,我猜我写过类似的东西可以与IE7一起使用...:

Imports SHDocVw 导入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

But today, with IE 11 it doesn't work.... I mean it still opens URLs in new windows. 但是今天,在IE 11中它不起作用...。我的意思是它仍然在新窗口中打开URL。

Do you have any ideas how to programatically force IE11 to open link in new Tab, not in new window? 您有任何想法如何以编程方式强制IE11在新选项卡中而不是在新窗口中打开链接吗?

Generally above code is OK except one detail - it should be: 通常,上面的代码可以,但有一个细节除外,它应该是:

If IE.Name = "Internet Explorer" Then... it is case sensitive. If IE.Name = "Internet Explorer" Then...区分大小写。

Finally my code looks like this: 最后,我的代码如下所示:

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

(...) (...)

And call: 并致电:

                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

And it works :) 它有效:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM