打开在现有的Internet Explorer中的新标签(命令行) [英] Opening a new tab on an existing Internet Explorer (from Command Line)

查看:810
本文介绍了打开在现有的Internet Explorer中的新标签(命令行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行在命令提示符(在Windows中),将打开Internet Explorer中的某些津贴的命令。

I would like to run a command on the command prompt (in Windows) that will open Internet Explorer with certain perks.

方案(从没有Internet Explorer中打开):

Scenario (starting with no Internet Explorer opened):


  • 运行IEXPLORE google.ca打开google.ca,作为一个新的选项卡,在Internet Explorer

  • 运行IEXPLORE yahoo.ca再次打开yahoo.ca,作为一个新的选项卡,在最近打开的Internet Explorer

最终的结果应该有一个Internet Explorer应用程序/窗口2标签。

End result should have 2 tabs on one Internet Explorer application/window.

我想上面的行为,但在运行IEXPLORE命令时,Internet Explorer将刚刚打开新窗口,而不是新的标签。我已经尝试了各种命令行选项和设置。

I would like the above behavior but Internet Explorer will just open new windows instead of new tabs when running the iexplore command. I have already tried various command line options and settings.

Java的code,如运行系统或的ProcessBuilder将用于执行此命令。任何其他的解决方案将是巨大的,以及。

Java code such as Runtime or ProcessBuilder will be used to execute this command. Any other solutions will be great as well.

注:我已经找到一种方法来获得这一行为,但它只会使用默认浏览器。我特别喜欢来指定,而不是依靠默认的浏览器Internet Explorer浏览器。 (启动/ d的www.google.ca)

Note: I have found a way to get this behavior but it will only work with the default browser. I would specifically like to specify the Internet Explorer browser instead of relying on the default browser. (start /d "" www.google.ca)

推荐答案

下一页的VBScript 可能会有帮助。说明在评论code。

Next VBScript could help. Explanation in commented code.

' VB Script Document ' http://stackoverflow.com/questions/31441974
' Opens blank page in a new MSIE tab and navigates to the URL if supplied. 
' Usage: ie [URL]
'        if saved as "IE.VBS" somewhere under PATH system environment variable.
'
option explicit
On Error Goto 0
Dim strMyUrl, intWExist, BrowserNavFlag, iRetNav2, objArgs, WshShell, IE, oIE, sTitle

Set objArgs = WScript.Arguments
If objArgs.Count > 0 Then
    strMyUrl = objArgs( 0)
Else
    strMyUrl = "about:blank"
End If

Set WshShell = WScript.CreateObject( "WScript.Shell")
Set IE  = Nothing
Set oIE = Nothing

intWExist = FindIE( strMyUrl, oIE) ' look for MSIE window pointer 

set IE = oIE
iRetNav2 = 0
Select Case intWExist
' Case 3
'   ''' 3 = MSIE window found, URL match, window title match
'   ''' (not implemented yet)
' Case 2
'   ''' 2 = MSIE window found, URL match
Case 1, 2, 3
    ''' 1 = MSIE window found, no URL match
    BrowserNavFlag = navOpenInNewTab ' 2048
    iRetNav2 = IE.Navigate2( strMyUrl, CLng( BrowserNavFlag), "_blank")
Case Else
    ''' 0 = MSIE window not found
    Set IE = CreateObject( "InternetExplorer.Application")
    BrowserNavFlag = 1
    iRetNav2 = IE.Navigate( strMyUrl)
End Select

IE.Visible = True

While IE.Busy
    Wscript.Sleep 100
Wend
While IE.Document.ReadyState <> "complete" '(obsolete?) Or IE.ReadyState <> 4
    Wscript.Sleep 100
Wend

sTitle = ""
intWExist = FindIE( strMyUrl, oIE) ' look for MSIE window title
' AppActivate method could fail (no error) if MSIE window runs minimized
'                               off topic for current question (31441974)
If Not sTitle = "" Then WshShell.AppActivate sTitle

Private Function FindIE( ByVal sUrl, ByRef oObj)
' parameters
' sUrl (input)  string
' oObj (output) object
' returns 
' 0 = any MSIE window not found - or found but not accessible   
' 1 = a MSIE window found
' 2 = 1 and address line match
' 3 = 2 and title match (not implemented yet)
    Dim ww, tpnm, tptitle, tpfulln, tpUrl, tpUrlUnencoded
    Dim errNo, errStr, intLoop, intLoopLimit
    Dim iFound : iFound = 0
    Dim shApp    : Set shApp = CreateObject( "Shell.Application")
    With shApp
        For Each ww In .windows
            tpfulln = ww.FullName
            If Instr( 1, Lcase( tpfulln), "iexplore.exe", vbTextCompare) <> 0 _ 
        and Instr( 1, UCase( tpfulln), "SCODEF:", vbTextCompare) = 0 _ 
        and Instr( 1, UCase( tpfulln), "CREDAT:", vbTextCompare) = 0 Then
                If iFound > 0 Then
                Else
                    Set oObj = ww
                End If
                tptitle = "x x x" : tpUrl = "" : tpUrlUnencoded = ""
                intLoopLimit = 10 ' to look for attributes max. intLoopLimit/10 seconds
                intLoop = 0
                While intLoop < intLoopLimit
                    intLoop = intLoop + 1
                    On Error Resume Next
                    tpnm = typename( ww.document)
                    errNo = Err.Number
                    If errNo <> 0 Then
                        'error if  page not response (yet)' 
                        errStr = "Error # " & CStr( errNo) _
                & " """ & Err.Description & """ 0x" & Hex( errNo)  
                        Wscript.Sleep 100
                    Else
                        iFound = 1
                        intLoopLimit = intLoop  ' end the loop and preserve loop counter
                        tptitle = ww.document.title
                        tpUrl = ww.document.URL
                        tpUrlUnencoded = ww.document.URLUnencoded
                        errStr = tpnm
            sTitle = tptitle
                    End If
                    On Error Goto 0
                Wend
                If Instr( 1, Lcase( tpnm), "htmldocument", vbTextCompare) <> 0 then
                    If Instr( 1, Lcase( tpUrl), Lcase( sUrl), vbTextCompare) <> 0 Then
                        Set oObj = ww
                        iFound = 2
                        ' looking for all matching MSIE URLs 
                        ' this may take considerable time amount
                        ' to speed up script running, uncomment next line "exit for"
                        exit for
                    Else
                    End If 
                End If
            Else
                ' a program reports the same shell.application property as "iexplore.exe"
                ' i.e. "explorer.exe", "HTML preview" in some editors etc.
            End If
        Next
    End With
    Set shApp = Nothing
    FindIE = iFound
End Function
' 
' http://msdn.microsoft.com/en-us/library/aa768360(v=vs.85).aspx
' BrowserNavConstants Enumerated Type
' Contains values used by the IWebBrowser2::Navigate
'                         and IWebBrowser2::Navigate2 methods.
' typedef enum BrowserNavConstants {
Const navOpenInNewWindow      = &h01, _
      navNoHistory            = &h02, _
      navNoReadFromCache      = &h04, _
      navNoWriteToCache       = &h08, _
      navAllowAutosearch      = &h10, _
      navBrowserBar           = &h20, _
      navHyperlink            = &h40, _
      navEnforceRestricted    = &h80, _
      navNewWindowsManaged    = &h0100, _
      navUntrustedForDownload = &h0200, _
      navTrustedForActiveX    = &h0400, _
      navOpenInNewTab         = &h0800, _
      navOpenInBackgroundTab  = &h1000, _
      navKeepWordWheelText    = &h2000, _
      navVirtualTab           = &h4000, _
      navBlockRedirectsXDomain= &h8000, _
      navOpenNewForegroundTab = &h010000
' } BrowserNavConstants;
' 

这篇关于打开在现有的Internet Explorer中的新标签(命令行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆