Jump to content

Random image?


Guest

Recommended Posts

I have a header which runs accross the top of my page. im interested to know that if i had a few versions of my header if i could get different headers to load at random when a page opens.

So for example if you press refresh or view a different page on the site you would view a diferent version of the header.

I've seen this sort of thing done within standard html. but have no idea how to do it myself. so i assume its achieveable in cubecart.

Link to comment
Share on other sites

I've done this in index.php for another site but never tried on a CC site:

<script language="JavaScript" type="text/javascript">

var theImages = new Array()

theImages[0] = 'your image source'

theImages[1] = 'your image source'

theImages[2] = 'your image source'

theImages[3] = 'your image source'

var j = 0

var p = theImages.length;

var preBuffer = new Array()

for (i = 0; i > p; i++){

preBuffer = new Image()

preBuffer.src = theImages

}

var whichImage = Math.round(Math.random()*(p-1));

function showImage(){

document.write('<img src="'+theImages[whichImage]+'" alt="header image">');

}

</script>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...