Javascript Retrieve Value Without Assigning Variable Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Javascript Retrieve Value Without Assigning Variable

12 Jun 2019, 09:06

Is it possible to retrieve a value directly from javascript without first assigning the value to a variable?

Example:

Code: Select all

WB.document.parentWindow.execScript("MyVar=JSON.stringify(SomeObjectReturnedFromJavascript")
MsgBox, % WB.document.parentWindow.MyVar

In this example, I can successfully get the value, however I would like to be able to query any value without first assigning variables to everything.

Is there a way to do that?
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: Javascript Retrieve Value Without Assigning Variable  Topic is solved

12 Jun 2019, 09:40

Try using eval:

Code: Select all

doc := ComObjCreate("htmlfile")
doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
MsgBox, % doc.parentWindow.eval("JSON.stringify({key: 'value'})")
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Javascript Retrieve Value Without Assigning Variable

12 Jun 2019, 09:51

teadrinker wrote:Try using eval
Perfect! It works great! Thank you!!
A_AhkUser
Posts: 1147
Joined: 06 Mar 2017, 16:18
Location: France
Contact:

Re: Javascript Retrieve Value Without Assigning Variable

12 Jun 2019, 19:31

Btw, for this specific example, you can write, for example:

Code: Select all

doc := ComObjCreate("htmlfile")
doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
MsgBox, % doc.parentWindow.JSON.stringify(doc.parentWindow.Array(5))
my scripts

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, RussF and 305 guests