Android Question How to call Wait For correctly with WebViewExtras

MaaMoz

Member
Licensed User
Longtime User
To all the friendly Anywhere Experts:

If make the following call using WebViewExtras:

wvx.ExecuteJavascript(wvYBiRead, "B4A.CallSub('getElmTopHeightText', true, document.getElementById('v1').offsetTop")

In the sub "getElmTopHeightText" I am setting some Global variables.

How do I use Wait For "getElmTopHeightText" to be sure the call is finished and the values are set?

Thank you
 
Last edited:

TILogistic

Expert
Licensed User
Longtime User
? B4X
B4X:
Private Sub RunJavaScript (js As String) As ResumableSub
    #if B4A
    WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
    Wait For Process_Html(html As String)
    Return html
    #Else If B4J
    Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
    #Else If B4i
    Dim sf As Object = WebView1.EvaluateJavaScript(js)
    Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
    Return Result
    #end if
End Sub

 
Upvote 1

Ivica Golubovic

Active Member
Licensed User
To all the friendly Anywhere Experts:

If make the following call using WebViewExtras:

wvx.ExecuteJavascript(wvYBiRead, "B4A.CallSub('getElmTopHeightText', true, document.getElementById('v1"').offsetTop")

In the sub "getElmTopHeightText" I am setting some Global variables.

How do I use Wait For "getElmTopHeightText" to be sure the call is finished and the values are set?

Thank you
With your approach you need to add javascript interface to catch B4A.CallSub. There is simplier approach, but WVExtra do not support this approach.
 
Upvote 0

MaaMoz

Member
Licensed User
Longtime User
I don't remember the exact event signature but you can use Wait For as an alternative to any event sub:
B4X:
wvx.ExecuteJavascript(wvYBiRead, "B4A.CallSub('getElmTopHeightText', true, document.getElementById('v1').offsetTop")
Wait For EventName_EventHere (Parameters...)

I thank you very much for your reply, your time to answer our questions.

Just to be sure I do understand this correctly: Is the following way of handling Wait For correct:

B4X:
    wvx.ExecuteJavascript(wvYBiRead, "B4A.CallSub('getElmTopHeightText', true, document.getElementById('v1').offsetTop, document.getElementById('v1').offsetHeight, document.getElementById('v1').innerText);")

    Wait For getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)

The called sub 'getElmTopHeightText' would then not need any code, just as shown below:

B4X:
Private Sub getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)
End Sub

Do I understand this correctly?

And: Thank you again
 
Upvote 0

MaaMoz

Member
Licensed User
Longtime User
With your approach you need to add javascript interface to catch B4A.CallSub. There is simplier approach, but WVExtra do not support this approach.
Hello Ivica
Thank you for your reply.
Naturally I had added the "javascript interface ... B4A.CallSub". This is the only way it will work :)

"simpler approach" - what would be this simpler approach?
 
Upvote 0

MaaMoz

Member
Licensed User
Longtime User
I thank you very much for your reply, your time to answer our questions.

Just to be sure I do understand this correctly: Is the following way of handling Wait For correct:

B4X:
    wvx.ExecuteJavascript(wvYBiRead, "B4A.CallSub('getElmTopHeightText', true, document.getElementById('v1').offsetTop, document.getElementById('v1').offsetHeight, document.getElementById('v1').innerText);")

    Wait For getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)

The called sub 'getElmTopHeightText' would then not need any code, just as shown below:

B4X:
Private Sub getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)
End Sub

Do I understand this correctly?

And: Thank you again

Just to share what I noticed:

B4X:
    wvx.ExecuteJavascript(wvYBiRead, "B4A.CallSub('getElmTopHeightText', true, document.getElementById('v1').offsetTop, document.getElementById('v1').offsetHeight, document.getElementById('v1').innerText);")

    Wait For getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)

The called sub 'getElmTopHeightText' would then not need any code, just as shown below:

B4X:
Private Sub getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)
End Sub

Above code returns all the values correctly even without writing any code in ...
B4X:
Private Sub getElmTopHeightText(strElmTop As String, strElmHeight As String, strElmText As String)
End Sub
... exactly as shown here.
In other words: It does not seem to be necessary to specifically return values in the "Sub getE.mTopHeightText(...)".
WebViewExtras does, in this case, return the values "automatically".

Thank you everyone who took the time to write. :)
 
Upvote 0
Top