Random Image Links

If you’d like to showcase random image buttons on your site, this would be a really useful snippet using inline javascript

Example

The HTML

Place where you’d like the images to show up

<script type="text/javascript">
var total_images = 4;
var random_number = Math.floor((Math.random()*total_images));
var random_img = new Array();
random_img[0] = '<a href="page1.html"><img alt="" src="https://i.postimg.cc/gJF2sXF5/88x31_anim3.gif"></a>';
random_img[1] = '<a href="page2.html"><img alt="" src="https://i.postimg.cc/DZkw6JkM/88x31_anim4.gif"></a>';
random_img[2] = '<a href="page3.html"><img alt="" src="https://i.postimg.cc/50d2gYdr/88x31_static.png"></a>';
random_img[3] = '<a href="page3.html"><img alt="" src="https://i.postimg.cc/qRVvwhVZ/88x31_static2.png"></a>';
document.write(random_img[random_number]);
</script>