webview with Javascript

tremara1

Active Member
Licensed User
Longtime User
I have been hunting around the forum for an answer as to whether or not you can send a value to a JavaScript function in a web view from b4a. I have not found the answer as yet. I looked at webviewextras, am I on the right track?
 

warwound

Expert
Licensed User
Longtime User
Your b4a code can execute any javascript in a WebView - so yes you can send data to the webpage javascript.

You can execute that javascript by prefixing the javascript statement(s) with the javascript: protocol and then using the WebView LoadUrl method.
Say you want to execute the javascript statement:
B4X:
myFunction(1, 20);

You can execute that statement using this syntax:
B4X:
MyWebView.LoadUrl("javascript:myFunction(1, 20);")

WebViewExtras has a method executeJavascript which you could use instead:
B4X:
MyWebViewExtras.executeJavascript(MyWebView, "myFunction(1, 20);")

Both techniques are identical - the executeJavascript method simply takes the javascript statement(s), adds the 'javascript:' protocol and then calls the WebVew LoadUrl method.

Martin.
 
Upvote 0

tremara1

Active Member
Licensed User
Longtime User
that was quick

Thanks that should help me no end......
 
Upvote 0
Top