本帖最后由 gently 于 2012-12-2 22:14 编辑
网上一堆的帮助都是autoit怎么调用ie里的js,就是没有找到IE里的js怎么调用autoit里的方法,函数,等等,所以我有些郁闷阿
我想要在IE里面用JS调用到autoit中的方法,比如获得网卡信息,比如弹出一个对话框,我想到的办法是使用window.status作代理,这总显得蹩脚,大牛们有更好的方法吗?#include "IE.au3"
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
GUICreate("test",@DesktopWidth-30)
;_IECreate(@ScriptDir & "\1.html", 1, 1, )
_IEErrorHandlerRegister("myerrhand")
Local $oIE = _IECreateEmbedded()
GUICtrlCreateObj($oIE, 10, 40, 600, 360)
GUISetState(@SW_SHOW)
_IENavigate($oIE, @ScriptDir & "\1.html?"&Random(1,10000))
While 1
$msg = GUIGetMsg()
Select
case $msg = $GUI_EVENT_CLOSE
GUIDelete()
Exit
EndSelect
$cmd_str = $oIE.document.parentWindow.status
if StringCompare("login::", $cmd_str) = 0 then
MsgBox(64, "main window","登录 (你成功的从JS调用了我 )")
elseif StringCompare("get_mac::",$cmd_str) = 0 then
$oIE.document.parentWindow.execScript('get_mac("我怎么知道你网卡地址是啥")')
ConsoleWrite("getMAC")
EndIf
$oIE.document.parentWindow.status=""
Sleep(10)
WEnd
func myerrhand()
;nothing to do
EndFunc
HTML代码如下:<!DOCTYPE HTML>
<html>
<head>
<title>Page Title</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript">
function ttt(){
var rand = Math.random()*10000;
document.getElementById("show").innerHTML="外部登录" + rand;
window.status="login::";
}
function get_mac(mac){
mac = mac || null;
if(!mac){
window.status = "get_mac::";
document.getElementById("show").innerHTML="正在获取网卡信息....";
return false;
}
document.getElementById("show").innerHTML=mac;
return true;
}
</script>
</head>
<body>
<h1 id="show">title random</h1>
<input type="button" value="登录" onclick="ttt()"/>
<input type="button" value="网卡地址" onclick="get_mac()"/>
</body>
</html>
期待高见 |