函数参考


_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

示例/演示


; *******************************************************
; 示例 1 - 附加到标题中含 "AutoIt" 的浏览器, 显示其 URL
; *******************************************************

#include <IE.au3>

Local $oIE = _IEAttach("AutoIt")
MsgBox(4096, "The URL", _IEPropertyGet($oIE, "locationurl"))

; *******************************************************
; 示例 2 - 附加到顶级文档的文本中含 "The quick brown fox"
;               的浏览器
; *******************************************************

#include <IE.au3>

$oIE = _IEAttach("The quick brown fox", "text")

; *******************************************************
; 示例 3 - 附加到嵌入另一窗口的浏览器控件
; *******************************************************

#include <IE.au3>

$oIE = _IEAttach("A Window Title", "embedded")

; *******************************************************
; 示例 4 - 附加到嵌入另一窗口的第三个浏览器控件
;               使用高级窗口标题语法以便使用标题中
;               含有字符串 'ICQ' 的第二个窗口
; *******************************************************

#include <IE.au3>

$oIE = _IEAttach("[REGEXPTITLE:ICQ; INSTANCE:2]", "embedded", 3)

; *******************************************************
; 示例 5 - 创建到所有当前浏览器实例的对象引用的数组
;               首个数组元素将包含找到的实例数
; *******************************************************

#include <IE.au3>

Local $aIE[1]
$aIE[0] = 0

Local $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(4096, "Browsers Found", "Number of browser instances in the array: " & $aIE[0])