Here is my first B4A library JSInterface.
JSInterface adds a new javascript interface to a WebView.
The new interface provides a bridge which allows your B4A code and any javascript (within a web page displayed in a WebView) to call each others' Subs/Functions.
Your B4A code can use the interface's execJS method to execute any javascript in the web page.
execJS returns no value to your B4A code.
And the web page javascript can use the interface's CallSub method to call a B4A Sub.
CallSub will return an empty string to your javascript if the B4A Sub returns nothing, otherwise CallSub will the Sub's return string to your javascript.
CallSub is an overloaded method - it can handle calling a B4A Sub with none, one or two string parameters.
Example javascript code:
I developed JSInterface so that i could save the state of a web page in a WebView and restore it when the device orientation changes but it has many other possibilities...
Martin.
[edit]Oooops forgot to say a big thanks to agraham for all his help![/edit]
JSInterface is no longer available or supported, please check out WebViewExtras.
JSInterface adds a new javascript interface to a WebView.
The new interface provides a bridge which allows your B4A code and any javascript (within a web page displayed in a WebView) to call each others' Subs/Functions.
Your B4A code can use the interface's execJS method to execute any javascript in the web page.
execJS returns no value to your B4A code.
And the web page javascript can use the interface's CallSub method to call a B4A Sub.
CallSub will return an empty string to your javascript if the B4A Sub returns nothing, otherwise CallSub will the Sub's return string to your javascript.
CallSub is an overloaded method - it can handle calling a B4A Sub with none, one or two string parameters.
Example javascript code:
B4X:
myJSNamespace.CallSub("myB4ASubName");
myJSNamespace.CallSub("myB4ASubName", "param 1");
myJSNamespace.CallSub("myB4ASubName", "param 1", "param 2");
I developed JSInterface so that i could save the state of a web page in a WebView and restore it when the device orientation changes but it has many other possibilities...
Martin.
[edit]Oooops forgot to say a big thanks to agraham for all his help![/edit]
JSInterface is no longer available or supported, please check out WebViewExtras.
Last edited: