Javascript Retrieve Value Without Assigning Variable Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
TheDewd
Posts: 1391
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?
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
teadrinker
Posts: 1633
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: 1391
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!!
Image Bulldozer - Sokoban inspired game from 1994 recreated in AutoHotkey.
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

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))

Return to “Ask For Help”

Who is online

Users browsing this forum: Bad husband, boiler, gecko, Google [Bot], Ian, metatron and 354 guests