peacemaker Expert Licensed User Longtime User Sep 23, 2018 #1 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...
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...
Erel B4X founder Staff member Licensed User Longtime User Sep 24, 2018 #2 It is indeed possible by injecting JavaScript with WebViewExtras library. Example of JS: https://stackoverflow.com/a/1358815 Upvote 0
It is indeed possible by injecting JavaScript with WebViewExtras library. Example of JS: https://stackoverflow.com/a/1358815
peacemaker Expert Licensed User Longtime User Sep 24, 2018 #3 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. Code: Copy 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: Sep 24, 2018 Upvote 0
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. Code: Copy 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.
peacemaker Expert Licensed User Longtime User Sep 24, 2018 #4 SOLVED: Code: Copy 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
SOLVED: Code: Copy 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
peacemaker Expert Licensed User Longtime User Sep 25, 2018 #5 Next question here - how to understand that Javascript has finished its work - search-and-replace task can be very long... Upvote 0
Next question here - how to understand that Javascript has finished its work - search-and-replace task can be very long...
DonManfred Expert Licensed User Longtime User Sep 25, 2018 #6 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
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.