WebViewExtras: need examples

Cableguy

Expert
Licensed User
Longtime User
Hi all,

I am trying to use martin's new WebViewExtras lib...
But the documentation is almost inexistant...
As a source of potencial info, I've taken the JSInyterface examples and tried to use them with WebViewExtras, but no luck...

Can anyone give me a working example, or demo app of using JInterface CallSub methods built-in WebViewExtra.

Thanks
 

warwound

Expert
Licensed User
Longtime User
Hi Cableguy.

I'm afraid i simply did not have the time to put together a better demo for WebViewExtras - work has to come before play!

Anyway you can use the JSInterface examples/demo as a basis for working with the newer WebViewExtras.

You just have to take into account a couple of changes:

1) The interface's CallSub() method signature has changed.
With JSInterface the CallSub() signature was:

CallSub(subName As String)
CallSub(subName As String, parameter1 As String)
CallSub(subName As String, parameter1 As String, parameter2 As String)
CallSub(subName As String, parameter1 As String, parameter2 As String, parameter3 As String)

The CallSub() signature in WebViewExtras is


Both JSInterface and WebViewExtras add an interface with a CallSub() method that your javascript can call with none, one, two or three String parameters.

WebViewExtras requires an extra boolean parameter though callUIThread.

If the B4A Sub that your javascript calls modifies your activity user interface then you must pass true for the value of callUIThread.

If the B4A Sub does not modify the UI then you can pass true or false as callUIThread.

However a Sub called with callUIThread as true cannot return any values from your activity to the javascript.
If callUIThread is false then values can be returned from your activity to the javascript.

The JSInterface CallSub() method can be pictured as if the callUIThread parameter is hardcoded to false.
With JSInterface your javascript is unable to call a B4A Sub that modifies the activity user interface.

Here's a thread that might help explain it all: http://www.b4x.com/forum/basic4android-updates-questions/11099-jsinterface-problem-msgbox.html

2) I refactored execJS() in JSInterface to executeJavascript() in WebViewExtras.

To answer your original question:
You can run the JSInterface examples with WebViewExtras by simply adding the false callUIThread parameter to your javascript:

B4X:
B4A.CallSub('MyB4ASub', false, 'some string value')

You will need to structure your B4A code so that Subs that return values to javascript do not modify the activity UI.

Martin.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Hi Paulo,

Have a look at the example in this thread WebView and GoogleMaps.

In the DispMap routine there are three CallSubs, calling subs in B4A (click, zoom_changed and center_changed events).

Hope this could help you.

Best regards.
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Thanks Guys...

Just got my first CallSub working, and am able to now retrieve the page html...
But if I was to change a pages User Enter field, like in a form, How that go?...
I've researched a bit, and foud a statemen..."innerHTML"...
So imagine I have im my form (loaded from http) a textbox with name=Username value="", how could I use webextras to change the value parameter??
 
Upvote 0

admac231

Active Member
Licensed User
Longtime User
Bear in mind that you've got the WebviewExtras working. The rest is javascript.

There is a ridiculous amount of documentation on javascript on the web. Look up
  • document.getElementsByName
  • document.getElementById
  • document.forms[]
Here's the code to change the value in a textbox to get you started:
B4X:
myInterface.executeJavascript(WebView1,"document.getElementsByName('Username')[0].value= 'Value you want';")
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Bear in mind that you've got the WebviewExtras working. The rest is javascript.

There is a ridiculous amount of documentation on javascript on the web.

Thanks admac...

Yes, I have noticed..My JScript knowleage is almost none, and I only know what ever I have needed to work with, like a simple "on submit" script...

I know there's a lot of "commands" in jscript to use, but since they are a bit "transparent" to the webview...I guess I have a long journey of trial and error a head, as my new project will use a lot of Jscript..
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
If you're manipulating a page on the fly then another useful javascript method is:

document.getElementsByTagName()

Tag name is the HTML element 'type', for example:

B4X:
var divs=document.getElementsByTagName('div');
var forms=document.getElementsByTagName(form');

Martin.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…