Slav the Claw
Slav the Claw

Reputation: 19

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).

I tried multiple ways, but the result is always the same like with:

Process.Start("iexplore.exe", address)

It works perfectly for Firefox, or Chrome, but for IE - it always opens new window for each link. Regardless IE is already opened or not.

Few years ago I wrote similar thing which worked with IE7 I guess...:

Imports 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.

Do you have any ideas how to programatically force IE11 to open link in new Tab, not in new window?

Upvotes: 0

Views: 1260

Answers (1)

Slav the Claw
Slav the Claw

Reputation: 19

Generally above code is OK except one detail - it should be:

If IE.Name = "Internet Explorer" Then... it is case sensitive.

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 :)

Upvotes: 1

Related Questions