www.webdeveloper.com
Results 1 to 3 of 3

Thread: Refresh an external javascript file from the server at intervals?

  1. #1
    Join Date
    Jan 2003
    Location
    UK
    Posts
    267

    Refresh an external javascript file from the server at intervals?

    Hi guys,

    I have a webpage in which certain content will be called from a javascript file.

    I will be linking to the file as follows:

    Code:
    <script type="text/javascript" src="js.js"></script>
    The js.js file will be updated by an admin in my office.

    Is it possible to have the js.js file called from the server periodically - say every 1800 seconds (to update the webpage without interrupting the user)?

    Also can there be a link to manually call the js.js file as well, in case a user doesn't want to wait 1800 seconds for the next update?

    I'm aware of the meta refresh tag but this would interrupt the user and erase text from the form fields that they need to use throughout the day.

    Your help is greatly appreciated.

  2. #2
    Join Date
    Sep 2011
    Location
    Bristol, England, United Kingdom
    Posts
    192
    I'm assuming you want a particular function in "js.js" to be called every 1,800 seconds? If so, you can simply include the JavaScript file on the page in question like you already have done, then use the setInterval function to call the given function each 1800 seconds.

    Code:
    <script type="text/javascript" src="js.js"></script>
    
    <script type="text/javascript">
    
    var refresh = setInterval
    (
        function()
        {
            your_function();
            your_other_function();
        }, 1800000 // milliseconds.
    );
    
    </script>
    Is that what you were looking for? If not, post more info.

  3. #3
    Join Date
    Mar 2009
    Posts
    452
    You can use AJAX to load external content on demand or regular intervals without reloading the page.

    you can also try jQuery getScript function http://api.jquery.com/jQuery.getScript/

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles