Ad

Javascript Round Robin Url Click

- 1 answer

i want to implement url click link random method by use javascript.

for example, if visitor A,B,C,D visited my site

and if click url link i want visitor visit my two website example1.com and example2.com randomly.

<area shape="rect" coords="140,350,890,440" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="http://somesite.com" target="_blank">

i found some javascript with array method but how can i modify it and can adopt to my case?

<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>
Ad

Answer

Why do you need JavaScript for this? If you are using php, it can be done there.

$sitenum = rand(1,2);

print <<<END
<area shape="rect" coords="140,350,890,440" target="_blank" rel="nofollow noreferrer" target="_blank" rel="nofollow noreferrer" href="http://somesite$sitenum.com" target="_blank">
END;
Ad
source: stackoverflow.com
Ad