Please help me to automatically change some images every time the user refreshes the website.
Like this website: https://weareunder.design/
whenever someone refreshes the website, the background images will be change automatically
I already try this: Change background image on refresh
but nothing work, I already change the class (the original class: slider-class to the same class as the images placeholder i want to change). and try to nest the code on , but nothing work.
You could use a JavaScript random method and a set of image url stored into an array to accomplish what you want. I’ve quickly build a codepen for you. You just need to replace the values in the array by the url of your images.
Thank you so much for the help, however when I tried to use it, the Images will come out in a sec and then gone, maybe there is something wrong about the how I use your code? (you can check the link above I share to take a look at the website)
right now your array reads: array = ["mobile-2", "dashboard-2"] those are not proper image URL. You need to copy paste the exact url of the webflow hosted images you’d like to use.
by the way, do you know how to make it 50% of the load?
I mean, the probability to change isn’t random, but 50%
so everytime the user refresh, it will refresh…
yes you could use the js.cookies API to set and get cookies. You can setup a cookie with the value of the URL of the image being displayed so that next time the user reload the page, the script will show the other url than the one that was previously saved.
Thank you so much, you save my day!
by the way, how if I want to add another image element in the same pages that have a trigger like above (change the images every time the website refreshes) and the probability to change the images,
Would you be able to include a read-only link for your site? I’m trying to achieve this too, would really appreciate being able to take a look at what you did!