0

I'd like to get the execute a javascript function using IE and get its value in VBScript. I have the following VBscript code (the solution has to be in 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()"? I'm aware that execscript always returns null. I could have the javascript write an element, and then fetch its value, but I'm sure there's a better way.

1 Answer 1

1

Create a variable in 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:

oIE.Document.parentWindow.execScript("var ultimateAnswer = function(){return 42;}")
msgbox oIE.Document.parentWindow.ultimateAnswer()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.