Tayfur Well-Known Member Licensed User Longtime User Aug 22, 2016 #1 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)")
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 Aug 22, 2016 #2 Tayfur said: 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)") Click to expand... 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
Tayfur said: 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)") Click to expand... 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...
b4x-de Active Member Licensed User Longtime User Jul 6, 2025 #3 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
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)
Erel B4X founder Staff member Licensed User Longtime User Jul 6, 2025 #4 This is a question from 2016. Better to not to bump it. Cross platform JavaScript execution: https://www.b4x.com/android/forum/threads/b4x-webview-ckeditor-rich-text-editor.133260/#content Upvote 0
This is a question from 2016. Better to not to bump it. Cross platform JavaScript execution: https://www.b4x.com/android/forum/threads/b4x-webview-ckeditor-rich-text-editor.133260/#content