I created an application on javafx, added javafx.scene.web.WebView browser, uploaded html content, in html content there is only one p tag

<p id="p1">text</p> <script> var ppp = document.getElementById("p1"); function f1(t) { ppp.innerHTML = t; } </script> 

It must be done so that this tag

constantly updated. Sorry could not easier or beautifully explained. But in my opinion you understand. You need to constantly update this tag through java

  • You have already written a function in the code that updates the text of the tag. So the question is completely incomprehensible; it is also not clear why Java is here at all - andreymal
  • constantly how is it? every second? - Vitaliy Shebanits
  • Yes, every second you need to update. I update webView.getEngine (). ExecuteScript ("f1 (" + Math.random () + ")"); - Bahodir Bahodir
  • You can of course update many times with Platform.runLater (), but this often causes an error. - Bahodir Bahodir
  • In javafx, there are classes such as Service and Task. These classes can help. But I do not know how with their help you can often update - Bahodir Bahodir

1 answer 1

setInterval restarts the function after each specified interval in milliseconds. One second = 1000; If there is no HTML inside the paragraph anyway, but only pure text, it will be more useful to use innerText (to avoid unnecessary checking for HTML, suddenly there is a kilometer text);

 const p1 = document.getElementById("p1"); setInterval(function () { p1.innerHTML = Math.random(); },1000); 
 <p id="p1">text</p> 

  • Rules, you don’t need to make changes to html content, I need java code - Bahodir Bahodir
  • Then I also understand html and javascript very well. Thanks for the answer, but I need to implement it on javafx - Bahodir Bahodir