Erick Kalugdan Member Licensed User Dec 3, 2015 #1 How do I... 1. Have my [app] execute and pass parameters to a [Javascript function inside the HTML inside a WebView] object? 2. Have a [Javascript inside the HTML inside a WebView] execute and pass parameters to a [Sub in my app]?
How do I... 1. Have my [app] execute and pass parameters to a [Javascript function inside the HTML inside a WebView] object? 2. Have a [Javascript inside the HTML inside a WebView] execute and pass parameters to a [Sub in my app]?
R Roycefer Well-Known Member Licensed User Longtime User Dec 3, 2015 #2 Is this for what you are looking: http://b4x.com/android/forum/threads/webviewextras.12453/ ? Upvote 0
Erick Kalugdan Member Licensed User Dec 5, 2015 #3 I think it's the one but am a newbie in B4A. When I downloaded the zip file WebViewExtras_v1_42.zip and extracted it, it only contained a JAR and an XML file. I don't know how to open it in B4A. Do you have a sample app that utilizes WebViewExtras_v1_42.zip? Upvote 0
I think it's the one but am a newbie in B4A. When I downloaded the zip file WebViewExtras_v1_42.zip and extracted it, it only contained a JAR and an XML file. I don't know how to open it in B4A. Do you have a sample app that utilizes WebViewExtras_v1_42.zip?
R Roycefer Well-Known Member Licensed User Longtime User Dec 5, 2015 #4 Copy those files into your Extra Libraries folder. Then right-click and hit Refresh in the Libraries tab in the IDE. Upvote 0
Copy those files into your Extra Libraries folder. Then right-click and hit Refresh in the Libraries tab in the IDE.
Erick Kalugdan Member Licensed User Dec 5, 2015 #5 Done. It now showed up in the Libraries tab. Thanks! I selected the library. Now... how do we use it in the code? Is it like: Code: Private WebView1 As WebView executeJavascript(webView1, "sayHello()") Upvote 0
Done. It now showed up in the Libraries tab. Thanks! I selected the library. Now... how do we use it in the code? Is it like: Code: Private WebView1 As WebView executeJavascript(webView1, "sayHello()")
R Roycefer Well-Known Member Licensed User Longtime User Dec 5, 2015 #6 Yes, that should work, provided there's a "sayHello()" function in the JavaScript. Upvote 0
Erick Kalugdan Member Licensed User Dec 9, 2015 #7 B4A to WebViewJS worked! WebViewJS to B4A worked too but I noticed that it can only call Subs without parameters like: B4A.CallSub('MySubName', true) But it did work when I call a Sub with parameters like: B4A.CallSub('MySubName(1,2,3)', true) Am I missing something here? Upvote 0
B4A to WebViewJS worked! WebViewJS to B4A worked too but I noticed that it can only call Subs without parameters like: B4A.CallSub('MySubName', true) But it did work when I call a Sub with parameters like: B4A.CallSub('MySubName(1,2,3)', true) Am I missing something here?
R Roycefer Well-Known Member Licensed User Longtime User Dec 9, 2015 #8 You have to do it like so: Code: B4A.CallSub("MySubName", true, 1,2,3); Upvote 0
stevel05 Expert Licensed User Longtime User Dec 9, 2015 #9 Have a look at the first post in Martin's library thread https://www.b4x.com/android/forum/threads/webviewextras.12453/ You have to pass the data in a specific format, the second parameter of the call states whether or not the sub will update the GUI. The remaining parameters are all Strings for passing data. So you can only pass 3 string parameters at most. Although these can be JSON strings, so you can wrap an array of simple values in a JSON string using JSONstringify in Javascript and pass it as one parameter and retrieve the values in the array using JSON parse from the B4a JSON library. Upvote 0
Have a look at the first post in Martin's library thread https://www.b4x.com/android/forum/threads/webviewextras.12453/ You have to pass the data in a specific format, the second parameter of the call states whether or not the sub will update the GUI. The remaining parameters are all Strings for passing data. So you can only pass 3 string parameters at most. Although these can be JSON strings, so you can wrap an array of simple values in a JSON string using JSONstringify in Javascript and pass it as one parameter and retrieve the values in the array using JSON parse from the B4a JSON library.
Erick Kalugdan Member Licensed User Dec 10, 2015 #10 Cool! It worked Now here's another one ... I observed that the "onload" event in a <BODY> tag does not work with a WebView. I wanted the WebView to focus on an input box and open the keyboard when the page loads. Here's my sample code: HTML: <script> function setFocusToTextBox(){ document.getElementById("mytext").focus(); } </script> <body onload="setFocusToTextBox()"> <input id="mytext" type="number" name="amount"> </body> When that HTML loads in the WebView, nothing happens. Am I missing something here? Upvote 0
Cool! It worked Now here's another one ... I observed that the "onload" event in a <BODY> tag does not work with a WebView. I wanted the WebView to focus on an input box and open the keyboard when the page loads. Here's my sample code: HTML: <script> function setFocusToTextBox(){ document.getElementById("mytext").focus(); } </script> <body onload="setFocusToTextBox()"> <input id="mytext" type="number" name="amount"> </body> When that HTML loads in the WebView, nothing happens. Am I missing something here?
R Roycefer Well-Known Member Licensed User Longtime User Dec 10, 2015 #11 Have you tried jQuery's document.ready() event? Upvote 0
Erick Kalugdan Member Licensed User Dec 10, 2015 #12 No. I try to avoid using JQuery to minimize the payload in my HTML Upvote 0