iOS Question [Solved] b4i CallSub

arifkibrit

Member
Licensed User
Hi, i try to search but couldn't find sorry if repost

i am using this code in B4A and it works for me but what i did and changed i couldn't trigger Subs

WebView1.ExecuteJavascript("document.getElementById('ELEMENT_ID').addEventListener('click', event => {B4A.CallSub('BuyMe',true,document.getElementById('ELEMENT_ID').target)})")

i tried so many things pls help me...
 

jahswant

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub RunJavaScript (js As String) As ResumableSub
    #if B4A
    WebViewExtras1.executeJavascript(WebView1, $"B4A.CallSub('Process_HTML', true, ${js})"$)
    Wait For Process_Html(html As String)
    Return html
    #Else If B4J
    Return WebView1.As(JavaObject).RunMethodJO("getEngine", Null).RunMethod("executeScript", Array(js))
    #Else If B4i
    Dim sf As Object = WebView1.EvaluateJavaScript(js)
    Wait For (sf) WebView1_JSComplete (Success As Boolean, Result As String)
    Return Result
    #end if
End Sub
 
Upvote 0

Duque

Active Member
Licensed User
Longtime User
I'm stuck on the same issue, I want to press a button in the web view and get the result in b4i.
According to the example, I have to run this in b4i, the clicks in the web view will not work?

I see that you have solved it, can you leave an example please.
 
Upvote 0

arifkibrit

Member
Licensed User
you should write a JS code in your webpage like
window.location.href = window.location + "&shareit";
and handle in B4i like
Private Sub WebView1_OverrideUrl (Url As String)

maybe have any other solution but i handle that way :)
 
Upvote 0
Top