函数参考
_IEAttach
--------------------------------------------------------------------------------
附加到指定的 Internet Explorer 实例,基于您所选择的模式按照字符串/子字符串匹配.
#include <IE.au3>
_IEAttach ( $s_string [, $s_mode = "Title" [, $i_instance = 1]] )
参数
$s_string 要搜索的字符串 (对于"embedded"或者"dialogbox",使用标题子字符串或者窗口句柄(HWND))
$s_mode [可选参数]: 指定搜索模式
Title = (默认) 主文档标题的子字符串
WindowTitle = 完整窗口标题的子字符串(替代文档标题)
URL = 当前网页的url或者url子字符串
Text = 当前网页body标记内的文本或者文本子字符串
HTML = 当前网页body标签内的HTML代码或者HTML代码子字符串
HWND = 浏览器窗口句柄
Embedded = 嵌入了控件的窗口的句柄或者标题子字符串
DialogBox = 模态/非模态的对话框的句柄或者标题子字符串
Instance = 忽略 $s_string, 从所有可用的浏览器实例中返回一个浏览器引用(通过匹配实例号)
$i_instance [可选参数]: 按照 $s_string 和 $s_mode 匹配的浏览器组/嵌入式浏览器组返回一个基于1开始的索引数组. 参考备注.
返回值
成功: 返回一个指向 InternetExplorer 对象的对象变量,嵌入式浏览器与对话框模块将返回一个窗口对象
失败: 返回 0 并设置 @ERROR
@Error 0 ($_IEStatus_Success) = 没有错误
5 ($_IEStatus_InvalidValue) = 无效值
7 ($_IEStatus_NoMatch) = 没有匹配项目
@Extended 包含无效参数的数量
注意/说明
_IEAttach provides the "dialogbox" parameter to attach to modal and modeless dialogs created by the browser. It is important to note that not all dialogs created through browser interaction can be attached to and controlled in this way. Many of these dialogs are actually standard windows and can be controlled through the traditional AutoIt window functions. A reliable way to tell the difference between these types of windows is to use the "AutoIt Window Info" tool to examine it -- if the window contains a control called "Internet Explorer_Server" then you can attach to it with this function, if it does not it is a standard window and traditional AutoIt windows functions must be used to control it.
HyperTextApplication (.hta) windows 也许可以用"embedded"选项来附加.
在 "dialogbox" 和 "embedded" 模式中可以用标准的Win*系列函数的高级窗口标题选择语法来代替标题子字符串搜索.
Use of "$i_instance" with the "embedded" mode: used to return a reference to a specific instance of a WebBrowser and is particularly useful when more than one exists in a particular window. If you pass a window title in $s_string using embedded mode, only the first window matching that title will be used. If the WebBrowser control you desire is in another window you must pass the HWnd of that window rather than the title, or use the advanced Window Title selection syntax available to the standard Win* functions.
Use of "$i_instance" with all modes other than "embedded": used to return a browser reference from a groups of all windows that match the criteria from $s_string and $s_mode. Instance order for DialogBox mode determined by the order returned by WinList() matching the title. For all other modes the Instance order is determined by the Shell.Windows collection.
"$i_instance" values > 1 are set to 1 and a warning message is displayed when used with "hwnd" mode or with "DialogBox" mode when an HWnd is passed in $s_string.
DialogBox and Embedded modes can be used to attach to standard browser windows, but the object returned is that if the top level Window in the browser and not the InternetExplorer object. Window objects do not offer access to all of the attributes of the InternetExplorer object (e.g. status text, address bar etc.). As well, if you attempt to use a function like _IENavigate on such an object you may receive COM errors due to the way that IE7 has implemented Tabs. It may be useful to find browser instances in this way, but it is recommended that you immediately use _IEAttach using one of the other modes and using information that you may have obtained from the Window object in order to get a reference to the associated InternetExplorer object.
相关
_IECreate, _IECreateEmbedded, _IEQuit
示例/演示
; *******************************************************
; Example 1 - Attach to a browser with "AutoIt" in its title, display the URL
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("AutoIt")
MsgBox(0, "The URL", _IEPropertyGet ($oIE, "locationurl"))
; *******************************************************
; Example 2 - Attach to a browser with "The quick brown fox"
; in the text of it's top-level document
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("The quick brown fox", "text")
; *******************************************************
; Example 3 - Attach to a browser control embedded in another window
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("A Window Title", "embedded")
; *******************************************************
; Example 4 - Attach to the 3rd browser control embedded in another window
; Use the advanced window title syntax to use the 2nd window
; with the string 'ICQ' in the title
; *******************************************************
;
#include <IE.au3>
$oIE = _IEAttach ("[REGEXPTITLE:ICQ; INSTANCE:2]", "embedded", 3)
; *******************************************************
; Example 5 - Create an array of object references to all current browser instances
; The first array element will contain the number of instances found
; *******************************************************
;
#include <IE.au3>
Dim $aIE[1]
$aIE[0] = 0
$i = 1
While 1
$oIE = _IEAttach ("", "instance", $i)
If @error = $_IEStatus_NoMatch Then ExitLoop
ReDim $aIE[$i + 1]
$aIE[$i] = $oIE
$aIE[0] = $i
$i += 1
WEnd
MsgBox(0, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) |