Android Question javascript in webview for skip images (without image placeholders)

Discussion in 'Android Questions' started by GERSON PINTO, Jun 24, 2019.

  1. GERSON PINTO

    GERSON PINTO Member Licensed User

    Hello!
    Initially I used the code:
    Code:
    WebView1.GetSettings.SetLoadsImagesAutomatically(False)
    Images are not actually displayed but the image name appears in its place.
    Searching the internet I found the following code in javascript that seems to solve the problem but I do not know how to implement it:

    source:https://stackoverflow.com/questions/6856522/how-to-force-webview-to-skip-images

    Code:
    webView.loadUrl("javascript:(function(){ var imgs=document.getElementsByTagName('img');"+
                            
    "for(i=0;i<imgs.length;i++) { imgs[i].style.display='none'; } })()");
    Could someone tell me how to implement this function in B4X or another way to do this? Thanks!
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    You are using WebViewExtra, right? You can execute JavaScript with ExecuteJavaScript (remove the javascript: scheme).
     
  3. GERSON PINTO

    GERSON PINTO Member Licensed User

    Yes, webViewExtras..
     
    Last edited: Jun 24, 2019
  4. GERSON PINTO

    GERSON PINTO Member Licensed User

    The JS code above not works and is equivalent to
    Code:
    WebView1.GetSettings.SetLoadsImagesAutomatically(False)
    or
    Code:
    WebView1.GetSettings.SetBlockNetworkImage(True)
    In fact the image is not shown but a broken image box appears!
    upload_2019-6-24_16-2-58.png
    How do I remove broken image box?

    Can anyone help?
     
  5. Brandsum

    Brandsum Active Member Licensed User

    Try this
    Code:
    Sub WebView_PageFinished (Url As String)
        
    WebViewExtras.ExecuteJavascript("for(i=document.images.length-1;i>=0;i--) { document.images[i].remove() }")
    End Sub
     
    Last edited: Jun 24, 2019
    Erel and GERSON PINTO like this.
  6. GERSON PINTO

    GERSON PINTO Member Licensed User

    Perfect! Works fine
    Thank you Brandsum!
     
    Brandsum 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