Android Question read value of function return in webview

Status
Not open for further replies.

Tayfur

Well-Known Member
Licensed User
Longtime User
I have like web page.(under below).
I loaded Webview this page.
And I want read return value.
How can I read this value?

Code:
<html>
<script type="text/javascript">
function myFunction(a, b) {
    return a * b;
}
</script>
<body> TEST</body>

I complate ,t, work code extrenal b4A code.So I cant read return value.

Code:
WebView_ex.executeJavascript(WebView_harita,"myFunction(3,5)")
 
I have like web page.(under below).
I loaded Webview this page.
And I want read return value.
How can I read this value?

Code:
<html>
<script type="text/javascript">
function myFunction(a, b) {
    return a * b;
}
</script>
<body> TEST</body>

I complate ,t, work code extrenal b4A code.So I cant read return value.

Code:
WebView_ex.executeJavascript(WebView_harita,"myFunction(3,5)")



My answer :

B4A loading code:
Code:
x=File.ReadString(File.DirAssets,"map_data2.txt")
    WebView1.LoadHtml(x)
    WebView_ex.addJavascriptInterface(WebView1, "B4A")

and add new sub
Code:
Sub MySubName(d As String)
    Log("return>>>"&d)

End Sub

in java file addded
Code:
<script type="text/javascript">
function myFunction(a, b) {
  //  return a * b;
B4A.CallSub('MySubName', true,a*b)
}
</script>
;

add buton in B4A . and pust it.

Code:
Sub Button1_Click
    WebView_ex.executeJavascript(WebView1, "myFunction(28,25)")
End Sub


its workssss...
 
Upvote 0
This can be also done this way:

B4X:
WebView_ex.executeJavascript(WebView1, $"B4A.CallSub('MySubName', true, myFunction(28,25))"$)

and even shorter:

B4X:
WebView_ex.executeJavascript(WebView1, $"B4A.CallSub('MySubName', true, myFunction(28,25))"$)
Wait For MySubName(result AS Int)
 
Upvote 0
Status
Not open for further replies.

Similar Threads

  • Article Article
Android Code Snippet Animation easing functions
Replies
3
Views
5K
  • Article Article
Android Code Snippet [B4X] Easing Functions
Replies
2
Views
4K
Replies
11
Views
16K
  • Question Question
Android Question AutoScale Code Module
Replies
70
Views
63K
Back
Top