#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0

    Question How refresh a item in website


    Hi there,

    I am a passionate weather and I'm creating a website for my weather station.
    Because I am a beginner in this world of design pages for websites I'm learning as I go creating pages.
    Now I wanted to create a page with the radar image from my area. But that was updated by the minute.

    What complicates me more is that the image is in the following direction:
    www. meteoelvas . com / RadarIM.php. And the script I'm testing does not work. Loads the image initially, but then will not upgrading to the most recent image, as you can see here:
    www. meteoelvas . com / wxradar.php.

    This is the code I am using:
    Code:
    <script type="text/javascript">
    // <![CDATA[ 
    var refreshrate = 60; // seconds between refresh
    var image = "RadarIM.php"; // image name
    var imgwidth = 600; // image width
    var imgheight = 600; // image height
    var imgalt = "Radar IM"; 
    function refresh() { document.images["pic"].src = image + "?" + new Date(); setTimeout('refresh()', refreshrate * 1000); } document.write('<img src="' + image + '" alt="' + imgalt + '" name="pic" id="pic" width="' + imgwidth + '" height="' + imgheight + '" style="border: none;" />'); if(document.images)window.onload=refresh; // ]]> </script>
    My thanks for possible helps.
  2. #2
  3. A Not To Shabby Code Smurf
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Aug 2008
    Posts
    1,188
    Rep Power
    184
    You need to give the image a unique query (to prevent image cache); as you were trying to do, but you were using the Date Object. So I replaced it with a number.

    Code:
    <script type="text/javascript">
    // <![CDATA[ 
    var refreshrate = 60; // seconds between refresh
    var image = "RadarIM.php"; // image name
    var imgwidth = 600; // image width
    var imgheight = 600; // image height
    var imgalt = "Radar IM";
    var refreshID = 0;
    refreshrate = refreshrate * 1000;
    function refresh()
    {
    refreshID++;
    document.images["pic"].src = image + "?rid=" + refreshID; 
    setTimeout('refresh()', refreshrate);
    }
    document.write('<img src="' + image + '" alt="' + imgalt + '" name="pic" id="pic" width="' + imgwidth + '" height="' + imgheight + '" style="border: none;" />'); 
    window.onload = function() {
    refresh();
    }
    // ]]>
    </script>

    Comments on this post

    • actioman agrees
    Last edited by web_loone08; February 20th, 2013 at 04:54 PM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    4
    Rep Power
    0
    web_loone08 many many thanks!!!

    So simple, but for those who do not know becomes complicated.

    And what the asks the code now? an image whatsoever, in a given time interval?

IMN logo majestic logo threadwatch logo seochat tools logo