A Random Ad Display Page : Random « Language Basics « JavaScript DHTML






A Random Ad Display Page

  
<HTML>
<HEAD>
<TITLE>Displaying Random Ads</TITLE>
<SCRIPT LANGUAGE="JavaScript"><!--
    urls = new Array("http://www.java2s.com",
                     "http://www.google.com",
                     "http://www.java2s.com")
    function insertAd() {
        adIX = Math.round(Math.random()*(urls.length-1));
        document.write('<A HREF="'+urls[adIX]+'">');
        document.writeln('</A>');
    }
// --></SCRIPT>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="JavaScript"><!--
insertAd();
// --></SCRIPT>
<H1>Displaying Random Ads</H1>
</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.Random URL
7.Find the random number in a range