Basically I just need to be able to notice page load, wait until page is loaded, and then add a value to a textbox. I noticed in his example he does this with function app_page(NewURL). he pulls the url of the page you're navigating to, and runs a function there disp_info() which modifies the text to show your ahk version.
However, when I try to do this to modify my settings.html page, I noticed it actually runs twice. Once when the link is clicked, and then on page load.
using button clicking works flawlessly but I'm just looking for a way to interact with the page on load. I've also tried using the html/js "onload=" event. However, that only works if I run a javascript alert first!
Here is his example script with comments
Code: Select all
#SingleInstance off
#NoTrayIcon
SendMode Input
#Include Lib\Webapp.ahk
__Webapp_AppStart:
;<< Header End >>
;Get our HTML DOM object
iWebCtrl := getDOM()
;Change App name on run-time
setAppName("My Webapp.ahk Application")
; cut auto run main thread.
Return
; Webapp.ahk-only Sensitive hotkeys
#IfWinActive, ahk_group __Webapp_windows
!Enter::
;!toggle
setFullscreen(!__Webapp_FullScreen)
Return
#IfWinActive
; Our custom protocol's url event handler
app_call(args) {
MsgBox %args%
if InStr(args,"msgbox/hello")
MsgBox Hello world!
else if InStr(args,"soundplay/ding")
SoundPlay, %A_WinDir%\Media\ding.wav
}
; function to run when page is loaded ;if put put a message box here, you'll see that it runs twice! how do I get it to execute only AFTER the actual page changes?
app_page(NewURL) {
wb := getDOM()
if InStr(NewURL,"index.html") {
disp_info()
}
}
disp_info() {
wb := getDOM()
Sleep, 10
x := wb.document.getElementById("ahk_info")
x.innerHTML := "<i>Webapp.ahk is currently running on " . GetAHK_EnvInfo() . ".</i>"
}
; Functions to be called from the html/js source
Hello() {
MsgBox Hello from JS_AHK :)
}
Run(t) {
Run, %t%
}
GetAHK_EnvInfo(){
return "AutoHotkey v" . A_AhkVersion . " " . (A_IsUnicode?"Unicode":"ANSI") . " " . (A_PtrSize*8) . "-bit"
}
Multiply(a,b) {
;MsgBox % a " * " b " = " a*b
return a * b
}
MyButton1() {
wb := getDOM()
MsgBox % wb.Document.getElementById("MyTextBox").Value
}
MyButton2() {
wb := getDOM()
FormatTime, TimeString, %A_Now%, dddd MMMM d, yyyy HH:mm:ss
Random, x, %min%, %max%
data := "AHK Version " A_AhkVersion " - " (A_IsUnicode ? "Unicode" : "Ansi") " " (A_PtrSize == 4 ? "32" : "64") "bit`nCurrent time: " TimeString "`nRandom number: " x
wb.Document.getElementById("MyTextBox").value := data
}
Code: Select all
; function to run when page is loaded
app_page(NewURL) {
wb := getDOM()
if InStr(NewURL,"settings.html") { ;This is actually going to run twice. Once when you click the link to launch "settings.html" and again just before the page loads.
disp_info()
}
}
disp_info() {
wb :=getDOM()
sleep,1000 ;This sleep actually takes effect BEFORE page load.
x := document.getElementById("settingOne")
x.value := "testing!"
}
Code: Select all
<!DOCTYPE html>
<html>
<head>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<link rel="stylesheet" href="assets/css/CSS.css">
</head>
<body onload="executeFunction()">
<span>Your name in SalesForce:</span> <input type ="text" id="settingOne"> </input>
<script>
AHK('executeAHKFunction'); //This will not execute unless you throw up a javascript alert! first.
<script>
</body>
</html>
executeAHKFunction() {
msgbox, Hello from ahk!
}