[英]Get value from a javascript function in VBscript
I'd like to get the execute a javascript function using IE and get its value in VBScript. 我想使用IE执行javascript函数并在VBScript中获取其值。 I have the following VBscript code (the solution has to be in vbscript):
我有以下VBscript代码(解决方案必须在vbscript中):
Dim oIE: Set oIE = CreateObject("InternetExplorer.application")
With oIE
.Visible = True
.Navigate (url)
End With
Do Until oIE.ReadyState = 4
wscript.sleep 100
Loop
oIE.Document.parentWindow.execScript("alert(function());") 'Get Return value
How can I get the value of "function()"? 如何获得“ function()”的值? I'm aware that execscript always returns null .
我知道execscript总是返回null 。 I could have the javascript write an element, and then fetch its value, but I'm sure there's a better way.
我可以让javascript写一个元素,然后获取它的值,但是我敢肯定有更好的方法。
Create a variable in javascript. 在javascript中创建一个变量。 The variable can be loaded with any value, object or function (as in this example).
变量可以加载任何值,对象或函数(如本例所示)。 In VBScript, you can retrieve it as a member of oIE.Document.parentWindow:
在VBScript中,您可以将其作为oIE.Document.parentWindow的成员进行检索:
oIE.Document.parentWindow.execScript("var ultimateAnswer = function(){return 42;}")
msgbox oIE.Document.parentWindow.ultimateAnswer()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.