Forum Moderators: open

Message Too Old, No Replies

how to refresh a external javascript file

         

laura2k

4:51 pm on May 12, 2004 (gmt 0)



hi,

on my page i call a javascript file called code.php as

<script src="code.php"></script>

the content of this code.php produces a document.write("") line that displays on my page. However, as the document.write writes text i wanted to know how i can use a javascript to refresh <script src="code.php"> every 20seconds or so. At the moment i am using a normal meta refresh tag which i dont like.

many thanx in advanced.

korkus2000

5:23 pm on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am not sure I understand what you mean. Do you want to refresh the page like a meta refresh but using javascript, or add a timeout that will execute the javascript every 20 seconds?

setTimeout [pageresource.com]

Location object [devguru.com]

Bernard Marx

5:31 pm on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it's on a timer, the document.write() would overwrite your page.
I don't really understand quite what you're up to either!

laura2k

5:33 pm on May 12, 2004 (gmt 0)



neither.

basically what i am trying to do is as follows:

i have a file called code.php when this code.php is called via a browser it displays the following:

<!--
document.write("Active: <b>25</b>")
//-->

the value 25 dynamically changes using the code of the php file.

I basically call the code.php file into my html file as follows:

<script src="code.php"></script>

this results to it display the following:

Active: <b>25</b>

But what i am trying to do is get this refreshed every 20 seconds. at the moment i have to refresh the whole page just to refresh this javascript file. I wanted to know if there was anyway to just refresh the file called

Bernard Marx

5:51 pm on May 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's an interesting approach. I've never seen that before. Thanks.
I mean calling a script with a php extension, so you can have a dynamic server include of sorts without changing the page extension from htm.

I don't think there's simple solution from then on though. One way (with 2 methods) boils it down to the usual 'inner-browing' problem of partially updating content without a full page refresh. With that you can use an invisible iframe, which gets tricky, or use an HTTP request.

I don't think you can go changing the src property of the script tag. If you could, you could perhaps keep calling it with a random, dummy query string to fool caching. The script would innerHTML your new content into a document element.

You could try createElement('script'), but you'd fill your document up with script tags after a while.