I am trying to implement a webbrowser control and inside the webbrowser control I am trying to implement a way to collect value from the input field.
This is a test webpage I have setted up: https://stc.opensyscon.com.au/test.html
The code of the webpage is this:
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
<script>
function getIdValue(lid)
{
var lret;
lret = document.getElementById(lid).value;
return lret;
}
/*
$(document).ready(function()
{
var lret;
lret = getIdValue('fname');
alert("Lret = " + lret);
});
*/
</script>
<html>
<head>
<title>Testing</title>
<head>
<body onload="autofill()">
Test page
<!--<button id="my_button" onclick="msg_box()">msg box</button>-->
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname"><br>
</form>
<script type"text/css">
function msg_box()
{
alert("I am an alert box!");
}
function autofill()
{
document.getElementById('fname').value="John"
}
</script>
</body>
</html>
And in powerbuilder (built on top of the demo code) here is a sample code:
Inside w_customers, ue_nav() event (this is being called as post event):
string lsret, ls_tagname
string webpage = "https://stc.opensyscon.com.au/test.html"
//wb_test.Navigate(webpage)
long ll_RootObject
long ll_item
JsonParser lnv_JsonParser
lnv_JsonParser = Create JsonParser
// Script to start navigation:
ib_navigate_called = FALSE
ib_navigate_started = FALSE
lsret = "start"
if wb_test.navigate(webpage) <> 1 then
// give error message
return
end if
yield()
//sleep(2)
do while lsRet <> "complete"
wb_test.EvaluateJavaScriptSync("document.readyState", REF lsRet)
lnv_JsonParser.LoadString(lsRet)
ll_RootObject = lnv_JsonParser.GetRootItem()
ll_item = lnv_JsonParser.GetChildItem(ll_RootObject, 2)
ls_tagName = lnv_JsonParser.GetItemString(ll_item)
if Pos(ls_tagName, '"complete"') = 0 then
exit
end if
loop
ib_navigate_called = TRUE
string ls_Json, ls_error
//int result
//
//wb_test.EvaluateJavascriptSync('document.getElementById("my_button")', ls_Json, ls_error)
//wb_test.EvaluateJavascriptSync('document.getElementById("fname").value', ls_Json, ls_error)
wb_test.EvaluateJavascriptSync('getIdValue("fname")', ls_Json, ls_error)
messagebox("Debug", "ls_Json = " + ls_Json)
//wb.test.document.getElementById(lid).value;
//
//
//if 1 = 2 then
// wb_test.Navigate(webpage)
//end if
//
Inside the webborwser control I have got two events:
navigationstart():
// We need to know it has really started navigating before we try to determine whether it has finished
if ib_navigate_called then ib_navigate_started = TRUE
navigationprogressindex():
// Navigation has been started. If it indicates 100 percent finished, check the document.readyState.
// If that is "complete", print the PDF file.
string lsRet
string webpage = "https://stc.opensyscon.com.au/test.html"
if NOT ib_navigate_started then return
if progressindex < 100 then return
EvaluateJavaScriptSync("document.readyState", REF lsRet)
if Pos(lsRet, '"complete"') = 0 then
return
end if
ib_navigate_started = FALSE // prevent recursion & thus doing any following steps twice
// now do whatever you need to do, it should be fully loaded!
string ls_Json, ls_error
int result
//wb_test.EvaluateJavascriptSync('document.getElementById("my_button")', ls_Json, ls_error)
//wb_test.EvaluateJavascriptSync('document.getIdValue("fname")', ls_Json, ls_error)
//
//
//if 1 = 2 then
// wb_test.Navigate(webpage)
//end if
Unfortunately the navigationprogressindex() event never gets called so I don't know what is up with that.
And in the ue_nav() event, I am getting value from ls_json only if I run through the debugger however running without the debugger it returns nothing.
I am trying to follow this guide:
However I don't know how to get navigationprogressindex() to work or if there is an alternative way to get the value of the input field into ls_json?