Javascript - Choosing a link at random

October 2016

Here below is a script that creates a hyperlink directing visitor to an address chosen at random from a list.

The following code is inserted between <HEAD> and </ HEAD> tags at the top of the page:

<SCRIPT Language="Javascript">
function Randomlink()
    Url = new Array;
    Url[0] = "";
    Url[1] = "http://www.";
    Url[2] = "http://www.";
    Url[3] = "http://www.";

    Chooselink = Math.round(Math.random() * (Url.length+1));[Chooselink],'_blank');

Don't forget to insert the following code within <BODY> and </BODY>) tags in order to display the link :

<A Href="#" onClick=" Randomlink (); return(false)">Random link</A>

Related :

This document entitled « Javascript - Choosing a link at random » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.