G33kDude / Neutron.ahk

AutoHotkey Web GUIs on Steroids
https://www.autohotkey.com/boards/viewtopic.php?f=6&t=76865
MIT License
201 stars 27 forks source link

How to insert variables in the html source #31

Open superuser7777 opened 1 year ago

superuser7777 commented 1 year ago

Neutron.ahk is a revolution in AHK GUI, thanks for a great library! I look forward to the implementation of WebView2! I am reading the documentation and samples and trying to figure it out through trial and error.

The code below didn't work.

How should I write the code? Or is there another better way?

*ahk

image_path := "D:\image.jpg"
neutron := new NeutronWindow(html,css,js,title)
neutron.Load("test.html")
neutron.Gui("+LabelNeutron +AlwaysOnTop +border +ToolWindow -Resize")
neutron.Show("w300 h300")

neutron.qs(".span").innerHTML := "<img src=`""%image_path%"`">" "</img>"   ;<--- Variables are printed as strings.
MsgBox, % neutron.doc.body.outerHTML
ExitApp

*html

<body>
<head>
<style>
span {
    width: 100%;
    height: 100%;
}
</style>
</head>
<div>
<span class="span"></span>   ;<--- Insert img tag
</div>
</body>
superuser7777 commented 1 year ago

I self-solved.

*ahk

imgItem := neutron.doc.createElement("img")
imgItem.src := image_path
neutron.qs(".span").appendChild(imgItem)