【问题标题】:Closing specific Browser tabs in Internet Explorer programmatically from AHK script从 AHK 脚本以编程方式关闭 Internet Explorer 中的特定浏览器选项卡
【发布时间】:2013-07-27 11:28:39
【问题描述】:

我有一个创建多个 IE 选项卡的 AHK 脚本,只是为了访问多个 URL。在程序结束时,我想关闭所有已打开的选项卡,同时保留所有与我的程序无关的选项卡。

我一直在努力研究如何编写代码。 WinClose 似乎想彻底关闭 IE。

非常重视这方面的任何帮助。我已经使用 AHK 几年了,它是我选择的编程语言!我喜欢我能用它做的事情!尤其是将代码编译成可移植的可执行文件是多么容易!

【问题讨论】:

    标签: internet-explorer autohotkey


    【解决方案1】:
    ; Example is taken from here:
    ; http://www.autohotkey.com/board/topic/67438-navigate-to-javascript/#entry426699
    
    VT_DISPATCH:=9, IID:="{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWINDOW2
    `(oIE:=ComObjCreate("InternetExplorer.Application")).visible:=True
    oIE.navigate("http://stackoverflow.com/questions/16327523/"
               . "closing-specific-browser-tabs-in-internet-explorer-programmatically-from-ahk-scr")
    
    While, oIE.ReadyState<>4 Or oIE.Busy
       Sleep, 500
    
    oWindow:=ComObj(VT_DISPATCH, ComObjQuery(oIE, IID, IID), 1)
    
    ; http://msdn.microsoft.com/en-us/library/aa741489(v=vs.85).aspx
    newWin:=oWindow.open("http://www.autohotkey.com", "_blank")
    While, % newWin.document.readyState!="complete"
       Sleep, 500
    
    MsgBox, 262144, % A_LineNumber, % newWin.document.title
    
    ; http://msdn.microsoft.com/en-us/library/aa741361(v=vs.85).aspx
    newWin.close
    MsgBox, 262144, % A_LineNumber, % oIE.document.title
    oIE.quit
    ExitApp
    

    【讨论】:

      【解决方案2】:

      这可能超出了您的兴趣,但您可以将COM 与 Internet Explorer 一起使用。 AutoHotkey 有一个ComObjCreate() 功能。使用 COM 函数就像直接编写 Internet Explorer 脚本,而不是使用窗口命令破解它的 GUI。

      Check out this SE question.

      另外,这是一个Autohotkey thread for using COM。

      这是来自文档的 COM 示例:

      ie := ComObjCreate("InternetExplorer.Application")
      ie.Visible := true  ; This is known to work incorrectly on IE7.
      ie.Navigate("http://l.autohotkey.net/")
      

      Here is Internet Explorer COM API.

      【讨论】:

        猜你喜欢
        • 2013-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-20
        • 2013-10-26
        • 1970-01-01
        • 2011-11-24
        • 2023-04-06
        相关资源
        最近更新 更多