Android Question Call B4A code from html code

pedropadel

Member
Licensed User
Longtime User
Hello!

I have a question: Is it possible call B4A code from html code? For example:

Dim page As String
page = "<p><a href='' onclick='... call MySub()....'>link to another html</a></p>"
WebView1.LoadHtml(page)


Sub MySub()
...
End Sub


Thank you very much!
 

wonder

Expert
Licensed User
Longtime User
Upvote 0

pedropadel

Member
Licensed User
Longtime User
I have the solution:

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("layoutMain")
Activity.AddMenuItem("flingScroll test", "FlingScroll")
WebView1.Height=100%y
WebView1.Width=100%x
MyWebViewExtras.addJavascriptInterface(WebView1, "B4A")
MyWebViewExtras.addWebChromeClient(WebView1,"")

Dim page As String
page = "<button onclick=" & Chr(34)& "B4A.CallSub('MySub',true)" & Chr(34) & ">Click Me</Button>"
WebView1.LoadHtml(page)

End Sub


Sub MySub()
........
End Sub

It is work!
 
Upvote 0
Top