Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Random image script help

    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:

    Code:
    	<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 =)

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,032
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    Well, you could do it with yet another array, but why not this as a practical matter:
    Code:
      ... 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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    moose86 (12-11-2009)

  • #3
    New Coder
    Join Date
    Dec 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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
    Last edited by moose86; 12-11-2009 at 10:24 PM. Reason: add more info

  • #4
    New Coder
    Join Date
    Dec 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    its all sorted now, thanks for the help
    Last edited by moose86; 12-11-2009 at 10:33 PM.

  • #5
    New Coder
    Join Date
    Dec 2009
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •