0
Thanks

A few words of thanks would be greatly appreciated.

Javascript - Choosing a link at random





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] = "http://www.ccm.net/index.php3";
    Url[1] = "http://www. ccm.net/wifi";
    Url[2] = "http://www. ccm.net/php";
    Url[3] = "http://www. ccm.net/forum/";

    Chooselink = Math.round(Math.random() * (Url.length+1));
    window.open(Url[Chooselink],'_blank');
}
//-->
</SCRIPT>



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>
0
Thanks

A few words of thanks would be greatly appreciated.

Ask a question
CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Related

This document, titled "Javascript - Choosing a link at random," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).

0 Comments