B4i JavascriptInterface

Discussion in 'iOS Code Snippets' started by tucano2000, Sep 22, 2018.

  1. tucano2000

    tucano2000 Active Member Licensed User

    B4i does not yet have a library to add a JavaScript Interface like WebviewExtras in B4A that uses addJavascriptInterface.

    Based in this thread https://www.b4x.com/android/forum/threads/b4i-addjavascriptinterface.72837/#post-462960


    I used this method that way and put this in the html file

    Code:
    <script>
    ...
        
    location.href = "#Page_Loaded";
    ...
    </ script>
    B4i to watch what is happening in the script html:

    Code:
    Sub Webview1_OverrideUrl (Url As String)
        
    If Url.Contains ("#Page_Loaded"Then
            
    'Do something
        Else if Url.Contains ("#showall"Then
            
    'Do something
        End If
    End Sub
    You can use anything with '#'
    #eat_apple
    #do_anything
    #showall

    the hash tag # does not redirect the browser to any location, remaining in the same state and at the same time, allowing a string parameter to be passed to the OverrideUrl event

    I hope it's useful. Like this to let me know that this worked for you too. ;)
     
    Last edited: Sep 22, 2018
    Erel likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice