我需要强制我的应用程序在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在新标签页中打开链接,而不是在新窗口中?
答案 0 :(得分: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
它有效:)