www.webdeveloper.com
Results 1 to 3 of 3

Thread: Script to change image at same time every day

  1. #1
    Join Date
    Nov 2011
    Posts
    16

    Script to change image at same time every day

    Hello,

    I need a script (must be in JavaScript) that changes an image at the same time every day of the week.

    Let's say it changes at 8am every day.

    I presume it would hold the 7 images in an array and would use something like Date.UTC to ensure everyone was seeing the same image? (Assuming people have their times set right).

    Is this something that's hard to do? I have tried to modify existing scripts but can't get anything to work.

    Any help appreciated.

    Thanks

  2. #2
    Join Date
    Jan 2009
    Location
    Sao Paulo, Brazil
    Posts
    15
    Maybe help you:

    Code:
    <script>
    function changeImage() {
    	var date = new Date();
    	var hour = date.getHours();
    	var week = date.getDay(); 
    	var images = new Array('image01.png','image02.png','image03.png','image04.png','image05.png','image06.png','image07.png');
    	var el = document.getElementById("image");
    	if (hour == 8)
    		el.src = images[week];
    }
    window.onload=changeImage;
    </script>
    
    <img id="image" src="">

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,441

    Lightbulb

    Code posted should work fine so long a all observers are in the same time zone.

    If not, consider UTC date and time functions with the timezoneoffset, if that is important to your display.
    See: http://www.w3schools.com/jsref/jsref_obj_date.asp

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