Random URL : Random « Language Basics « JavaScript DHTML






Random URL

  

<HTML>
<HEAD>
<SCRIPT language="JavaScript">
var rand_url= new Array()
rand_url[0]="http://www.java2s.com";
rand_url[1]="http://www.google.com";
rand_url[2]="http://www.msn.com";

var rand_num= Math.floor(Math.random()*2);
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT language="JavaScript">
   document.write("<A HREF='"+rand_url[rand_num]+"'>"+rand_url[rand_num]+"</A>");
</SCRIPT>

</BODY>

</HTML>

   
    
  








Related examples in the same category

1.Unique Random Numbers
2.Unique Random Sets
3.Math Random number: a random number between 0 and 1
4.Random number from 0 to 10: a random number from 0 to 10 using the random() and round()
5.Random link
6.A Random Ad Display Page
7.Find the random number in a range