Open tab in existing IE instance

前端 未结 3 1261
醉梦人生
醉梦人生 2020-12-16 18:37
$ie = New-Object -com internetexplorer.application

Everytime i open a new website with this object(ie every time when script runs) it is opened in

3条回答
  •  一整个雨季
    2020-12-16 18:51

    First you have to attach to the already running Internet Explorer instance:

    $ie = (New-Object -ComObject "Shell.Application").Windows() |
          Where-Object { $_.Name -eq "Windows Internet Explorer" }
    

    Then you Navigate to the new URL. Where that URL is opened is controlled via the Flags parameter:

    $ie.Navigate("http://www.google.com/", 2048)
    

    Edit: In case 2 or more IE instances are running (additional tabs count as additional instances as well) the enumeration will return an array, so you have to select a particular instance from the array:

    $ie[0].Navigate("http://www.google.com/", 2048)
    

提交回复
热议问题