Change the background of the site daily automatically

0

We are finalizing a system that in the login part has a background with a certain image, but we are trying to make every day a new image appears, the same as in Bing. Can you do this in javascript or jquery? The change of image would be daily and not every access.

    
asked by anonymous 12.09.2017 / 15:50

2 answers

3

Hello, you have, you can change each background by the day of the week:

Script code:

<script type="text/javascript"><!--
    var imlocation = "Images/";
    function ImageArray (n) {
        this.length = n;
        for (var i =1; i <= n; i++) {
            this[i] = ' '
        }
    }
    image = new ImageArray(7);
    image[0] = 'sunday.PNG';
    image[1] = 'monday.PNG';
    image[2] = 'tuesday.PNG';
    image[3] = 'wednesday.PNG';
    image[4] = 'thursday.PNG';
    image[5] = 'friday.PNG';
    image[6] = 'saturday.PNG';
    var currentdate = new Date();
    var imagenumber = currentdate.getDay();
    document.write('<img src="' + imlocation + image[imagenumber] + '">');
</script>

Create a folder named Images and add the images with each name of the week, you can change the names to Portuguese.

    
12.09.2017 / 16:11
2

It is possible, in the following example I make a background for each day of the week:

var images = [
  'https://www.cleverfiles.com/howto/wp-content/uploads/2016/08/mini.jpg',
  'https://upload.wikimedia.org/wikipedia/commons/1/1e/Stonehenge.jpg',
  'https://upload.wikimedia.org/wikipedia/commons/2/2a/Junonia_lemonias_DSF_upper_by_Kadavoor.JPG',
  'https://c1.staticflickr.com/6/5216/30091409642_42af7bf19f_b.jpg',
  'https://c2.staticflickr.com/6/5612/31035985960_096daebcb7_b.jpg',
  'http://www.kendirfuar.com/img/sabitler/eskiler/8-0b1555db83aa481e518543aac4af0ddf.jpg',
  'https://i.stack.imgur.com/XeIwO.png'
];

var week_day = new Date().getDay();
document.body.style.backgroundImage = 'url(' +images[week_day]+ ')';

In today's case (Tuesday) week_day returns 2, that is, the third image of our array images , with Sunday being 0 second is 1 , etc ...

DOCS

    
12.09.2017 / 16:19