View Full Version : Random image script help

12-11-2009, 09:43 PM
Hi, im wondering if anyone can help me, i have a random image script and it works fine, apart from when you click on the images they link to the right place but ALL go to _self

I want [2],[3]and[6] to link to the places they are already linking to but _blank NOT _self, does anyone know how to do this, it would be a massive help :)

Below is the code for the script i am using:

<script language="JavaScript">
function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="images/layout/bottom gallery.png"
myimages[2]="images/layout/bottom facebook.png"
myimages[3]="images/layout/bottom twitter.png"
myimages[4]="images/layout/bottom team.png"
myimages[5]="images/layout/bottom whats on.png"
myimages[6]="images/layout/bottom forum.png"

//specify corresponding links below
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>')


Thanks in advance =)

Old Pedant
12-11-2009, 10:11 PM
Well, you could do it with yet another array, but why not this as a practical matter:

... above here same ...
var ry = 1 + Math.floor(Math.random()*myimages.length);
var link = imagelinks[ry];
var target = ( link.substring(0,4) == "http" ) ? "_blank" : "_top";
document.write( '<a href="'+link+'" target="'+target+'"><img src="'+myimages[ry]+'" border="0"></a>')

Your random picker was broken. You would never have picked image/link number 6. And you would pick 1 twice as often as 2 through 5. Now fixed.

12-11-2009, 10:22 PM
yer it works but it somehow copies the page and puts it next to it

here is what i mean:

whats happened?? :S

that page is ment to be centered as it is when you click on MEET THE TEAM in the top menu

12-11-2009, 10:24 PM
its all sorted now, thanks for the help :)

12-11-2009, 10:38 PM
i gots another question, is it poss for you to set a .swf file per month?


Jan - 1.swf
Feb - 2.swf
Mar - 3.swf

thanks again in advance :)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum