I want to write a javascript function to change background image after every 24 hours for 30 days.
For example, I have 4 images, image1.jpg, image2.jpg, image3.jpg and image4.jpg.
I want image1.jpg to be displayed on Monday. Then by midnight I want to swap automatically to image2.jpg and so on.
I was thing to use a java script function like this
function changeImg() {
var now = new Date(),
hours=now.getHours(),
minutes=now.getMinutes(),
seconds=now.getSeconds(),
dayD=now.getDate(),
dayM=now.getMonth()+1,
datY=now.getFullYear(),
timer = setTimeout("changeImg()",200);
}
var imgArray = new imgArr[xyz.png,abc.png,........,30.png]
Now my question is that how to change automatically image after 24hours. If I use a for loop to increment the counter to change the image will it work. And is it correct way to do this and if i am using this way Is the timer will maintain the previous counter value.
I want that every day at 9:00 am the background image will change.