Android Question Delete lines in page loaded in webview (javascript)

GERSON PINTO

Member
Licensed User
Hello guys!
I need delete or remove the first two lines in a webpage loaded in webview
Is It possible with executejavascript using webviewextras?

B4X:
Dim js As String = "????"
    WebViewExtras1.executeJavascript(WebView1, js)

can anyone help?
 

Lucas Eduardo

Active Member
Licensed User
Hello, yes, its possible. You can do this inspecting this line that you want to delete and find her id or class for example. There are another options too.
the line code will look like this with id
WebViewExtras1.executeJavascript("document.getElementById('footer').style.display = 'none';")
with class name, note that if you choose remove by class you have to put the position [0] case there are more than one same class
WebViewExtras1.executeJavascript("document.getElementsByClassName('pageNavLinkGroup')[0].style.display = 'none';")
 
Upvote 0

GERSON PINTO

Member
Licensed User

Thanks

Unfortunately there would be no way for me to inspect each page.
maybe another approach...
How could I do to replace one word with another or white space?
What string has to be passed to the executejavascript command for this?
I tried the code below but it didn't work...

B4X:
Dim javascript As StringBuilder
   javascript.Initialize
   javascript.Append("var originalText = 'wrong word';")
   javascript=javascript.Append("var newText = originalText.replace('correct word', '');")
   javascript=javascript.Append("document.querySelector('.output').textContent    = newText;")
   webviewextras1.executeJavascript(WebView1,javascript)
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
stringbuilder works a little differently; just keep calling javascript.append("some_string").append("another_string) until you're set. no constant re-assignment. then refer to javascript.tostring() in your executeJavascript call.

whether or not your javascript is correct is another story.

you can, optionally, use javascript.append() as separate statements (as you have done), if that makes it easier for you to read, but without the re-assigning
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…