...

View Full Version : Random image script help



moose86
12-11-2009, 10: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()
imagelinks[1]="gallery.html"
imagelinks[2]="http://www.facebook.com/tos.php?api_key=fcddbaae811ef62bf3c4fb2ac7b1fd07&next=http%3A//dailyphoto-1402445175.us-east-1.elb.amazonaws.com/dailyphoto/applications/buffer/id%3A1/pid%3A2828044108236222753/from%3Apublisher.attachment.own.image?ref=nf&v=1.0&canvas#/group.php?gid=87957825200&ref=ts"
imagelinks[3]="https://twitter.com/groundzereo"
imagelinks[4]="team.html"
imagelinks[5]="whatson.html"
imagelinks[6]="http://groundzero.forumotion.co.uk/"

var ry=Math.floor(Math.random()*myimages.length)

if (ry==0)
ry=1
document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0></a>')
}

random_imglink()
//-->
</script>

Thanks in advance =)

Old Pedant
12-11-2009, 11: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.

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

here is what i mean:
http://www.ralph-flynn.co.uk/tom/

whats happened?? :S

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

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

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

E.G

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

thanks again in advance :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum