How to display a random image, once per session

Hello @theenrico and @KBConcepts There is the new link:

https://blocs.pt/a_helpblocusers/@JDW2

Sorry,

About how to do it:

  1. Place a new html code bric and inside put the following code:
<script type="text/javascript">
var total_images = 6;
var random_number = Math.floor((Math.random()*total_images));
var random_img = new Array();
random_img[0] = '<img src="img/image1.jpg">';
random_img[1] = '<img src="img/image2.jpg">';
random_img[2] = '<img src="img/image3.jpg">';
random_img[3] = '<img src="img/image4.jpg">';
random_img[4] = '<img src="img/image5.jpg">';
random_img[5] = '<img src="img/image6.jpg">';
document.write(random_img[random_number]);
</script>
  1. Add as many images that you want, so now you have an issue, no images appears in blocs or in preview, so for that you have 2 solutions:
    a) Add images to asset manager and place that pictures in somewhere in project even in a page that you don’t publish (This way you can preview in blocs)
    or…
    b) Add them manually after export in folder img. (You can’t preview in blocs)

And voila …

With links in images the same explanation as above but with this code:

<script type="text/javascript">
var total_images = 6;
var random_number = Math.floor((Math.random()*total_images));
var random_img = new Array();
random_img[0] = '<a href="page1.html"><img src="img/image1.jpg"></a>';
random_img[1] = '<a href="page2.html"><img src="img/image2.jpg"></a>';
random_img[2] = '<a href="page3.html"><img src="img/image3.jpg"></a>';
random_img[3] = '<a href="page4.html"><img src="img/image4.jpg"></a>';
random_img[4] = '<a href="page5.html"><img src="img/image5.jpg"></a>';
random_img[5] = '<a href="page6.html"><img src="img/image6.jpg"></a>';
document.write(random_img[random_number]);
</script>

Hope it helps you…

3 Likes