2013-05-01 112 views
1

我有一个AHK脚本,用于创建多个IE选项卡,仅用于访问多个URL。在程序结束时,我想关闭所有已打开的选项卡,同时打开任何与我的程序无关的选项卡。以编程方式从AHK脚本中关闭Internet Explorer中的特定浏览器选项卡

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

对此真的很重视。我已经使用AHK几年了,这是我选择的编程语言!我喜欢我能用它做什么!特别是将代码编译为便携式可执行文件是多么容易!

回答

0
; 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 
0

这可能比您感兴趣的要多,但您可以使用Internet Explorer的COM。 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

相关问题