How to show the value of a variable that is in another page html [closed]

0
The problem is this: I need to see some values that are updated every 3 seconds in a file that can be .html , .csv , .txt or .css , any extension that can be viewed in the Notepad.

It would look like this

./diretório/Pagina1.html ou .csv ou .txt

var x=10

var y=20

var z=30

./diretório/Pagina2.html

Temperatura X [show var x]

Temperatura Y [show var y]

Temperatura Z [show var z]

NOTE: When updating the value in the variable on page 1 you would have to update the value in the tag on page 2.

Thank you.

    
asked by anonymous 20.12.2015 / 20:06

1 answer

0

As you just want to capture the value of the variable in any extension that opens in Notepad, I advise you to do this with javascript .

In the .js file you should have:

var x = 10;
var y = 20;
var z = 30;

And your .html page should have access to this .js file. You get it like this:

 <script src="arquivo1.js" ></script>

I assumed that it is in the same directory as your html.

Then just have your tags show the variables:

HTML

<p id="x"></p>
<p id="y"></p>
<p id="z"></p>

Javascript

document.getElementById("x").innerHTML = x;
document.getElementById("y").innerHTML = y;
document.getElementById("z").innerHTML = z;

If you want these values to be updated without the need to reload the page, with an interval of 3s, as you said in the question, just add this to your javascript inside the html page:

Element.prototype.remove = function() {
  this.parentElement.removeChild(this);
}
setInterval(function() {
  var script = document.createElement("script");
  script.src = "require.js";
  document.getElementsByTagName("body")[0].insertBefore(script, document.getElementsByTagName("body")[0].childNodes[0]);
  document.getElementsByTagName("script")[0].remove();
  document.getElementById("x").innerHTML = x;
  document.getElementById("y").innerHTML = y;
  document.getElementById("z").innerHTML = z;
}, 3000)
    
20.12.2015 / 20:55