How to force reload of "temperature.js" data

D

Derek Ross

Hello,

Say I have a server that's saving the CPU temperature to
'temperature.js' once a second. The contents of the file is one single
line:

var temperature = "35.5";

And it changes as the temperature changes.

Is it possible to have an HTML file in the same directory as the
"temperature.js" file, that's reading the file once a second and then
provides a crude realtime update of the temperature value?

The HTML result would look something like:

TEMPERATURE:
35.5
35.6
35.4
35.7
36.1
....etc, page continues appending temperature by the second...

I know how to used .innerHTML to append values to a list, but I'm having
trouble getting my "temperature.js" script to reload and execute once a
second, so that the "temperature" variable is always up-to-date. It
seems that the temperature is reloaded only when the whole HTML page is
loaded.

Any assistance would be appreciated,
Thanks,
Derek.
 
C

Chris Riesbeck

I know how to used .innerHTML to append values to a list, but I'm having
trouble getting my "temperature.js" script to reload and execute once a
second, so that the "temperature" variable is always up-to-date. It
seems that the temperature is reloaded only when the whole HTML page is
loaded.

Try

<script ... id="data" src="temperatures.js"></script>

To reload

document.getElementById("data").src = "temperatures.js"

To do this periodically, use setTimeOut()
 
C

Chris Riesbeck

Chris Riesbeck said:
Try

<script ... id="data" src="temperatures.js"></script>

To reload

document.getElementById("data").src = "temperatures.js"

Tested a bit more -- this only seems to work in IE,
not Mozilla or Opera

So follow the usual hack and a frameset with an invisible
frame with an HTML file that loads the javascript, and
then reload that frame as needed.
 
B

Bernard Lechler

I would create a page with two frames. A main frame and a hidden
frame. The hidden frame would have an onload event handler that
appends the temperature to the document displayed in the main frame.
It would then pause for an arbitrary period, and reload itself.

Bernie
 
C

Csaba2000

One approach was covered in this newsgroup 2 days ago under the title:
How to hit a server in the background
If you can't find it, do a search on google - it's already there.

In your case, since you're only returning a single datum, I'd
be highly inclined to test out whether cookies load with .js files
Please do report back if you go this route.

Good Luck,
Csaba Gabor from New York
 
D

Derek Ross

Thank you for the advice.

FWIW, I've also had some success with calling the js script in a
popunder window, but I think I'll go with the frameset idea. Many
people disable popups, which would pose a problem for me.

Derek.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top