Android Question webview_PageFinished Result string from web

scsjc

Well-Known Member
Licensed User
Longtime User
I use:

B4X:
dim webview1 as webview
webview1.Initialize("webview1")
webview1.LoadURL("http://xxx")

Sub webview1_PageFinished(urlpage As String)
   Log (urlpage)
end sub


is possible get the result string from a web ?
 
Last edited:

scsjc

Well-Known Member
Licensed User
Longtime User
Thanks for your answer...

i'm try a get data from javascript inside in html....



B4X:
<script>
$(document).ready(function(){
    $.post("https://xxx.xxx", {
        client_name: 123,
        user_id: 1,
        invoice_group_id: 1
    },
    function(data) {
        var response = JSON.parse(data);
        if (response.success == '1')
        {
            document.getElementById("invoiceid").innerHTML = response.invoice_id;
        }
    });
});
</script>
<p id="invoiceid"></p>



but, only get a html string, dont get result
 
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
You will need to set up a Javascript Interface. With that, you can call JS functions from B4A and call B4A Subs from JS. It's the same functionality.

Just use the search function and youll find some good tutorials on how to do that. If you have any further questions to that, feel free to ask me, im using JS interfaces very often.
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
You will need to set up a Javascript Interface. With that, you can call JS functions from B4A and call B4A Subs from JS. It's the same functionality.

Just use the search function and youll find some good tutorials on how to do that. If you have any further questions to that, feel free to ask me, im using JS interfaces very often.

I will search if I find what you tell me.
If you have an example by hand, or some link please add it
thank you very much
 
Upvote 0

nobbi59

Active Member
Licensed User
Longtime User
Heres an Example:

You can see Sytax and description here: https://www.b4x.com/android/forum/threads/webviewextras.12453/

B4X:
Sub Globals
       Private wvJS as WebView
       Private wwX as WebViewExtras
End Sub

Sub Activity_Create(isFirst as Boolean)
       wwx.addJavascriptInterface(wv, "B4A")
       wwx.addWebChromeClient(wv,"chromeclient")
End Sub

Sub wvJS_PageFinished(Url as String)
       wvJS.LoadUrl("javascript:bridgeactive()")
End Sub

Sub msgbox(title as String, text as String)
       MsgBox(text,title)
End Sub


In JS:

B4X:
function bridgeactive(){
    B4A.CallSub("msgbox",true, "Title","It works!");
   //Set CallUIThread to true because youre modifying the UI
   //You can also get a Return Value, but only if its set to false
}
 
Upvote 0

scsjc

Well-Known Member
Licensed User
Longtime User
Heres an Example:

You can see Sytax and description here: https://www.b4x.com/android/forum/threads/webviewextras.12453/

B4X:
Sub Globals
       Private wvJS as WebView
       Private wwX as WebViewExtras
End Sub

Sub Activity_Create(isFirst as Boolean)
       wwx.addJavascriptInterface(wv, "B4A")
       wwx.addWebChromeClient(wv,"chromeclient")
End Sub

Sub wvJS_PageFinished(Url as String)
       wvJS.LoadUrl("javascript:bridgeactive()")
End Sub

Sub msgbox(title as String, text as String)
       MsgBox(text,title)
End Sub


In JS:

B4X:
function bridgeactive(){
    B4A.CallSub("msgbox",true, "Title","It works!");
   //Set CallUIThread to true because youre modifying the UI
   //You can also get a Return Value, but only if its set to false
}

Thanks a lot, im try it with this way.
:)
 
Upvote 0
Top