Android Question webview page modify on-the-go

peacemaker

Expert
Licensed User
Longtime User
HI, All

Who knows WEB well - suggest, please, how to replace some text in the page that opened in a webview ?
I guees, by Javascript maybe possible something...
 

peacemaker

Expert
Licensed User
Longtime User
All my test with replacing whole the HTML by JS injection - no success. Yes, i can get the web-page text, but after modification i can only make WebView.LoadHTML for sure.
And links do not work, as it's now local page is opened.
Task is read any web-page with partially edited text, translated into another language.

B4X:
WebViewExtras1.executeJavascript(WebView1, "document.body.parentElement.innerHTML = " & QUOTE & Html & QUOTE)

A new HTML replaces the whole the page, yes, but edited HTML got from the sourced page is not assigned, not got by WebView.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
SOLVED:

B4X:
Sub WebView1_PageFinished (Url As String)
        Dim Javascript As String = $"document.body.innerHTML = document.body.innerHTML.replace(/text_to_search/gi, "text_to_replace");"$
        WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Next question here - how to understand that Javascript has finished its work - search-and-replace task can be very long...
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
1. Please start a new thread for a new question.
2. You are free to put a script there which calls a b4a sub when finished. See webviewextras library example on how it works.
 
Upvote 0
Top