Android Question WebviewExtras2 AddJavascriptInterface Not working But working to WebviewExtras

drgottjr

Well-Known Member
Licensed User
Longtime User
both the javascriptinterface and executejavascript work with webviewextras2. what are you doing to make them not work? don't describe what you're doing, show code.
 
Upvote 0

alfaiz678

Active Member
Licensed User
The code is big, and I've shortened it.
And he mentioned what was required of him.

1646984509873.png

B4X:
Dim WebView1 As FlingableWebView
 Private myInterface As WebViewExtras
 
    Private Sub B4XPage_Created (Root1 As B4XView)
    myInterface.Initialize(WebView1)
    End Sub
 
Sub WebView1LoadHtml
    WebView1.LoadHtml("<html><body>Hello world!</body></html>")
    myInterface.AddJavascriptInterface(WebView1,"B4A")

End Sub

Private Sub BShare_Click
    Dim jsStatement As String = "B4A.CallSub('processHTMLShare', true, document.documentElement.innerText)"
    myInterface.executeJavascript( jsStatement)
End Sub

Sub processHTMLShare(html As String)
    Dim in As Intent
    in.Initialize(in.ACTION_SEND, "")
    in.PutExtra("android.intent.extra.TEXT",  html   )
    in.SetType("text/plain")
    in.WrapAsIntentChooser("Share")
    StartActivity(in)
End Sub
 
Last edited:
Upvote 0

drgottjr

Well-Known Member
Licensed User
Longtime User
you say webviewextras2 javascriptinterface does not work.
attached find example showing that it does. it uses
some of your code.

1) i don't know what flingable webview is. (see edit below)
2) i don't use b4xpages

my example runs on my android 12 device, sdk30. you'll have
to figure out the differences between your code and mine.

i am only responding to your statement that javascriptinterface
with webviewextras2 does not work. i have nothing to say about
the rest of your code. sorry.

-------------------------------------------------------------------------------------------
edit: i downloaded flingablewebview library and substituted it for our core webview. seemed to work ok.

as for ssl, i'm not seeing it mentioned in the code you posted...
 

Attachments

  • webview2.zip
    7.6 KB · Views: 55
Last edited:
Upvote 0

alfaiz678

Active Member
Licensed User
Thank you it now
The problem was here
B4X:
  myInterface.AddJavascriptInterface(WebView1,"B4A")

And the right code, as you mentioned.
B4X:
myInterface.AddJavascriptInterface( DefaultJavascriptInterface1, "B4A")
Thank you
 
Upvote 0
Top