【问题标题】:Referring Internet Explorer - Using Internet Explorer Object Model引用 Internet Explorer - 使用 Internet Explorer 对象模型
【发布时间】:2013-07-29 11:00:24
【问题描述】:

我想在运行时创建一个 Internet Explorer 对象,我需要它来引用或查找已在当前会话中打开的浏览器对象 (IE)。

使用下面的代码作为启动创建一个新的 Internet Explorer 对象并打开一个浏览器并引用它。但是如何创建一个 Internet Explorer 对象来帮助我们识别会话中打开的现有浏览器,而不是打开一个新的浏览器窗口。

Set IE = CreateObject("InternetExplorer.Application")

谁能帮我解决这个问题。谢谢。

【问题讨论】:

    标签: vbscript


    【解决方案1】:

    您可以将Shell.Application 对象用于find an already running IE instance

    Set sh = CreateObject("Shell.Application")
    For Each wnd In sh.Windows
      If InStr(1, wnd.FullName, "iexplore.exe", vbTextCompare) > 0 Then
        Set ie = wnd
        Exit For
      End If
    Next
    

    以上内容将附加到找到的第一个实例。如果您删除 Exit For,它将改为附加到找到的最后一个实例。

    【讨论】:

    • 谢谢您,需要更多信息,当您说第一个实例和最后一个实例时,您的意思是 Internet Explorer 首先打开和最后打开,它是否完全按照创建时间的顺序匹配?
    • 经过快速测试:是的,看起来它们是按创建顺序排列的(新标签在这里算作新实例)。
    猜你喜欢
    • 1970-01-01
    • 2017-06-06
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-24
    • 1970-01-01
    相关资源
    最近更新 更多