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

GERSON PINTO

Member
Licensed User
Hello!
Initially I used the code:
B4X:
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

B4X:
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!
 

GERSON PINTO

Member
Licensed User
The JS code above not works and is equivalent to
B4X:
WebView1.GetSettings.SetLoadsImagesAutomatically(False)
or
B4X:
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?
 
Upvote 0

Brandsum

Well-Known Member
Licensed User
Try this
B4X:
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:
Upvote 0
Top