what is it or how do I correct this javascript please, I'll explain: in a webview what I need to do is replace part of a text within a paragraph among several, I need to do it in the DOM on the fly and respecting the attributes of the paragraph that only change the internal part of the text that I want, the paragraph is identified with its respective Id, I have tried many scripts in many ways and I cannot get the result that I need, the script that I currently publish replaces the entire page and not only the text of the paragraph that I'm telling you, thank you very much in advance
first execute this script to go to the location of the paragraph on which I want to make the change, this script works perfectly for me:
WebViewExtras1.ExecuteJavascript("var e = document.getElementById("&Starter.ll&");e.scrollIntoView({behavior:'smooth', block:'start'});")
this is the script that doesn't work for me or it works but incorrectly:
you're replacing, but you're not assigning the replacement to anything. you need:
JavaScript:
var e = WebViewExtras1.ExecuteJavascript("document.getElementById("&Starter.ll&");
e.innerText = e.innerText.replace('"&Starter.mtext&"','"&linmod&"');"
you're replacing, but you're not assigning the replacement to anything. you need:
JavaScript:
var e = WebViewExtras1.ExecuteJavascript("document.getElementById("&Starter.ll&");
e.innerText = e.innerText.replace('"&Starter.mtext&"','"&linmod&"');"
I already tried this before and now again and it does exactly the same thing, apparently the complete DOM replaces me, here I show you in a general way the structure
general structure of the DOM within which I want to replace that part of text for example;:
<html>
<body>
<hr color=#070707>
<!-- before and after the paragraph there are more elements -->
<div id='d1'>
<p id='1' aligne='justify' style='color:#9B9B9B'>
TEXT O THE PARAGRAPH WHERE I NEED TO DO THE REPLACE EXACTLY FOR EXAMPLE THE WORD REPLACEME
</p>
</div>
<!-- before and after the paragraph there are more elements -->
</body>
</html>
my code works fine. i took your example, made a web page, loaded it and replaced "REPLACEDME" with "endbyte" using the code i suggested to you
(see image #3)
my code works fine. i took your example, made a web page, loaded it and replaced "REPLACEDME" with "endbyte" using the code i suggested to you
(see image #3)
I'm testing and reviewing in detail because although everything here looks good and it doesn't work for me either the way you are doing it or in other ways, the strange thing is that this is the only script with which I have had problems in all my experiences, Beware, a detail that I half commented on my question is that I need to do it on the fly, that is, without reloading the page, I am checking because even with your example, reloading the page does not work for me, I must have misplaced something here, REVIEWING...
either you will solve the problem by yourself, or you'll post the project and let others try.
based on your explanation, it is possible to do a search/replace with javascript injection.
if there are other things that we do not know about, it will be difficult to help you.
O resolverás el problema por ti mismo, o publicarás el proyecto y dejarás que otros lo intenten.
Según su explicación, es posible hacer una búsqueda / reemplazo con inyección de JavaScript.
Si hay otras cosas que no conocemos, será difícil ayudarte.
either you will solve the problem by yourself, or you'll post the project and let others try.
based on your explanation, it is possible to do a search/replace with javascript injection.
if there are other things that we do not know about, it will be difficult to help you.
I have not solved it, I have an html that I load to a webview and I simply need to change a text of a certain paragraph and that the change is reflected immediately without having to reload the page, that simple but it seems that in webview it is not so easy or something is missing in the script to reflect the change to the DOM, thanks for your collaboration, if I manage to find the solution myself, of course I will publish it to help others who may need the same or something similar
SOLVED : there was no way to make the change only on the specific text I wanted so I had to make the change externally on the entire paragraph and then replace it using innerHTML, no way that's weird webview