Sorry for before I ment js not is but auto correct
How to use js/could you use js?
Thanks
Js and ahk
-
- Posts: 4295
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Js and ahk
What are you going to do with it?
Re: Js and ahk
Hey,
You can include functionalities from other languages using DllCall()
You can include functionalities from other languages using DllCall()
-
- Posts: 43
- Joined: 28 Nov 2022, 01:31
Re: Js and ahk
Not anything at the moment just figured it will be useful for more complex stuff
Re: Js and ahk
Js as in Javascript?
You can use the MS version (JScript) with COM
The core of the code is:
On line 2 it creates one internet explorer object (think like it opens IE but without it's gui)
On line 3 it includes the header meta equivalent to accept newer Jscript commands (by default it is IE6 if I'm not wrong)
On line 4 it runs the ie function eval ( htmlfile.parentWindow.eval() ). You can use directly functions from JS using like that.
Optionally you can go directly with the COM object only.
The code is not javascript and has it's own quirks when using.
You need to be mindfull when doing hybrid because it's easy to forget if your sintax is currently on AHK layer or in JS layer.
You can use the MS version (JScript) with COM
Code: Select all
JS_Eval(str) {
;htmlfile := ComObject("htmlfile") ;v2 sintax
htmlfile := ComObjCreate("htmlfile") ;v1 sintax
htmlfile.write("<meta http-equiv='X-UA-Compatible' content='IE=edge'>")
return htmlfile.parentWindow.eval(str)
}
JS_Eval("alert('testing');alert('another test!')")
On line 2 it creates one internet explorer object (think like it opens IE but without it's gui)
On line 3 it includes the header meta equivalent to accept newer Jscript commands (by default it is IE6 if I'm not wrong)
On line 4 it runs the ie function eval ( htmlfile.parentWindow.eval() ). You can use directly functions from JS using like that.
Optionally you can go directly with the COM object only.
Code: Select all
htmlfile := ComObjCreate("htmlfile") ;v1 sintax
;htmlfile := ComObject('htmlfile') ;v2 sintax
htmlfile.write("<meta http-equiv='X-UA-Compatible' content='IE=edge'>")
JS := htmlfile.parentWindow
JS.eval("var testVar = 'something' ")
JS.alert("testing")
JS.alert("another test! " . JS.testVar )
msgbox % JS.testVar
You need to be mindfull when doing hybrid because it's easy to forget if your sintax is currently on AHK layer or in JS layer.
Last edited by Leafk on 30 Nov 2022, 10:02, edited 1 time in total.
-
- Posts: 4295
- Joined: 29 Mar 2015, 09:41
- Contact:
Re: Js and ahk
Here v1 thread!
Nope.
Re: Js and ahk
Whoops my bad. I'll edit to make it v1 compliant.