View Full Version : General random image generator for 6 images

09-24-2011, 02:58 PM
Hi could someone please help?... I am a total beginner to javascript... but does anyone know of a code, including links to an image folder, for displaying 6 fullscreen images in random order without repeat for a given user?

I've seen specific examples using shuffle on the site, but could anyone write a general code for any given images?

Many thanks in advance :)

09-24-2011, 04:53 PM
Try this one... Hope it may resolve your problem....

<DIV ID="imgPlaceHolderDiv"></DIV>
var imgSrcArray = ['image1.gif','image2.gif','image3.gif','image4.gif','image5.gif','image6.gif','image7.gif','image8.g if'];

function showRandomly(thisObject, imgArray, imgPlaceHolderId, delay, autoRepeat) {
var meta = [], count = 0;
var objHolder = document.getElementById(imgPlaceHolderId);
var self = thisObject;

function getRandomIndex() {
var index = -1;
for (; ; ) {
if(count == imgArray.length) {
if(autoRepeat) {
meta = [];
count = 0;
} else {
index = -1;
index = parseInt(Math.random(imgArray.length)*(imgArray.length > 10 ? 100: 10), 10);
if(index < imgArray.length && meta[index] == null) {
meta[index] = index;
return index;

this.init = function() {
var index = getRandomIndex();
if(index < 0) return false;
objHolder.innerHTML = '<img src="' + imgArray[index] + '" alt="' + imgArray[index] +'" height="' + (screen.availHeight/2) + '" width="' + (screen.availWidth/2) + '">';
setTimeout(self + ".init()", delay);

var shuffle = new showRandomly('shuffle', imgSrcArray, 'imgPlaceHolderDiv', 1000, false);

Thanks & Regards,
Niral Soni

09-24-2011, 05:02 PM

This may be your answer. Your feedback is appreciated.

<script language="JavaScript">
function random_imglink(){
var myimages=new Array()


var imagelinks=new Array()

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')

Generating random picture including it's own link each time the page refreshed. But I want something that when I click the image, it opened new page / tab / window, just like when you click outside link from this forum.

Chrish Hardwick

09-24-2011, 05:21 PM
Thank you so much for your quick response!

I tried implementing this into my index page (http://timperceval.com/guiran) and the image appears as you have scripted but is just aligned top left.

Is there anyway to make it adjust to all navigator screens and go to full screen automatically?

Also to add a duration for the appearance of the image?

Ideally I would like to make it fade out to load the main javascript of the site while displaying the image instead of the usual loading.gif.

Is that possible?

Again any help would be greatly appreciated!

09-24-2011, 08:30 PM
Thanks Chrish,

I am still hoping to get the fullscreen option and fade out while loading main javascript if possible?



09-24-2011, 11:16 PM
Hi is it possible to load images to fullscreen for the above random image generator script?

I noticed that the images being rejected in the random selection process are still visible as frames on the screen, which is kind of ugly. Is there any way to prevent them being visible until the actual image is randomly selected?

Also the above script doesn't seem to end when the main script loads. Is it possible to do that?

Many thanks in advance! :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum