2 Replies - 1834 Views - Last Post: 22 August 2012 - 11:41 AM

#1 spearfish   User is offline

  • Monkey in Training
  • member icon

Reputation: 10
  • View blog
  • Posts: 746
  • Joined: 10-March 08

Link Randomizer

Posted 02 April 2008 - 06:54 PM

Description: As always, this is formatted in a nice HTML document :-)

You will need to modify the array "links" to suit your needs.

Open up a script and call function disp_links(number) to bring in the links wherever you want them. The parameter is the number of links you want displayed. They will be brought in as they are listed in the array, so if you plan to pull multiple links, be sure to put a space or a
after each of the elements of the array.

Any HTML you're storing as an array element must use single quotes.

Also, you can use ANYTHING with this script, not just links. Whatever HTML you store as an array element (including pictures, paragraphs, linked pictures) will be brought out to wherever the function is called from.

-SpearDisplays a random link (or image, or paragraph, or anything from that matter!) on a web page.
<script type='text/javascript'>
var links=new Array();
links[0]="<a href='http://www.yahoo.com/'>Yahoo</a> ";
links[1]="<a href='http://www.dreamincode.net/'>Dream.In.Code</a> ";
links[2]="<a href='http://www.example.com/'>Example.com</a> ";
links[3]="<a href='http://www.conquerclub.com/'>Free online risk!</a> ";
links[4]="<a href='http://www.google.com/'>The best search engine in the world</a> ";
function disp_links(number) {
	for (i=1;i<=number;i++) {
		var k = Math.floor(Math.random()*links.length);
<p><script type='text/javascript'>disp_links(1);</script></p>

Is This A Good Question/Topic? 0
  • +

Replies To: Link Randomizer

#2 chuckjessup   User is offline

  • D.I.C Regular

Reputation: 34
  • View blog
  • Posts: 380
  • Joined: 26-October 09

Re: Link Randomizer

Posted 27 August 2010 - 03:01 PM

Well this defiantly is a cool piece of code, Thank you so much, my J.S. books didn't have it I am so happy that it works exactly as I needed it to... JF
Was This Post Helpful? 0
  • +
  • -

#3 Deepglue555   User is offline

  • D.I.C Head
  • member icon

Reputation: 8
  • View blog
  • Posts: 118
  • Joined: 13-April 09

Re: Link Randomizer

Posted 22 August 2012 - 11:41 AM

I have a gallery of images that I want to randomize between two links, 1 link the page of the full size image the other link is a redirect. The redirect will be the same for all the images in the gallery. I want it to go to the redirect 20% of the time and to the full size image the other 80% of the time. I'm guessing it could be done in php. I suppose I could paste this code for each image in the gallery but there must be a better way to do it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1