Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts

    Forcing an image to refresh

    Hello, I have a website that shows images off of an ftp server that my computer has set up. What I need to know is how can I force the browser to redownload an image? For instance, my ftp server has a file called: "Welcome.jpg" and every minute the jpg is changed to be something else, but it is still named "Welcome.jpg". When I try to use javascript to set the source of the image, the image isnt' re-downloaded because it has the same path as before. Any ideas as to how I could force the browser to redownload the image instead of looking in its cache? Thanks a lot.

  • #2
    Join Date
    Sep 2003
    Thanked 0 Times in 0 Posts
    This script will add a querry (?) and the UTC time to the end of the image URL.
    Resulting in a unique image URL according to the date and time it is downloaded.
    <script type="text/javascript">
      function noCache(){
        var myImage = new Image();	
            myImage.src = 'Welcome.jpg';
        var clocktime = new Date();
        var utchours = clocktime.getUTCHours();
        var utcminutes = clocktime.getUTCMinutes();
        var utcseconds = clocktime.getUTCSeconds();
        var utcyear = clocktime.getUTCFullYear();
        var utcmonth = clocktime.getUTCMonth()+1;
        var utcday = clocktime.getUTCDate();
        var utctime = utcyear+''+utcmonth+''+utcday;
            utctime += utchours+''+utcminutes+''+utcseconds;
          isNew = myImage.src;
               document.images['noCache'].src = myImage.src+'?'+utctime;
          else{document.images['noCache'].src = document.images['noCache'].src;
    <BODY onload="noCache()">
    <img name="noCache" src="Welcome.jpg" width="" height="" alt="">

  • #3

    How to use this with rollovers?

    I've been using Willy's autorefresh script for a while now and it works great!

    Now I'd like to implement this together with a rollover script because I'd like to update several thumbnail pictures with new ones but the file names stay the same.

    The problem is that all rollover scripts which I have found so far use only one image tag...

    As I understand your script, the "original" and the "over" images would need *separate* IDs so that they would autorefresh.

    Does anybody know if there is a way to do an autorefresh of rollover images without having to resort to CSS based rollovers?

    How to do this?

    Thanks, martin

  • #4
    New to the CF scene
    Join Date
    Dec 2005
    Thanked 0 Times in 0 Posts
    I would suggest creating a hidden image with a src that is equal to that of the rollover image. Try this and see if it helps, I have not tried it but it might be a good starting point. Good luck!


    Posting Permissions

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