If these banners are coming via the database, in MySQL for example there is the function ORDER BY RAND()
, where for each request it would bring a random item.
If you are only viewing images from a folder, you could list the images in a array
in JavaScript , and create a variable that generates a random value according to the amount of images, and this value would pull the specific item, for example:
var imagens = ["Imagem 1", "Imagem 2", "Imagem 3"]
var j = Math.floor((Math.random() * items.length) + 1);
Here you would call the image as follows:
imagens[j - 1]
I put -1 because J would generate values between 1 and the amount of items, however the keys of array
are 0 to the amount of itens-1
.
This way, whenever the page is reloaded, the script will be re-executed, so it will always display a different image (or not, it is random, so it is possible to repeat the same image two or more times).