Android Question read value of function return in webview

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?

B4X:
<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.

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

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?

B4X:
<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.

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



My answer :

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

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

End Sub

in java file addded
B4X:
<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.

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


its workssss...
 
Upvote 0
Top