Generating Frame Source by random selection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DruidWanderer
    New Member
    • Dec 2008
    • 3

    Generating Frame Source by random selection

    I'm attempting to create a frame that loads a page with a specific variable based on a random number, but I can't seem to get it to work. Any help would be greatly appreciated.
    Here's what I've got so far:

    Code:
    <html>
    
    <head>
    <title>Main Page</title>
    </head>
    
    <frameset rows="100%">
    	<script language='javascript'>
    <!--
    var sponsorid=new Array()
    
    sponsorid[0]="main.html?id=sp1"
    sponsorid[1]="main.html?id=sp2"
    sponsorid[2]="main.html?id=sp3"
    sponsorid[3]="main.html?id=sp4"
    sponsorid[4]="main.html?id=sp5"
    
    var frmSrc=sponsorid[Math.floor(Math.random()*sponsorid.length)]
    
    document.write('<frame src="'+frmSrc+'" scrolling=auto frameborder="no" border=0 noresize>');//-->
    </script>
    	<noframes>
    	<body>
    <script language='javascript'> 
    window.location = "main.html?id=sp1"; 
    </script>
    	</body>
    	</noframes>
    </frameset>
    
    </html>
    Any ideas where I'm going wrong?
    Last edited by acoder; Dec 17 '08, 06:47 PM. Reason: changed quote to code tags
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    You need to review proper fame tag syntax. Your JavaScript looks fine, but it will never be executed inside frame tags like this. You will have to put the JavaScript inside an HTML file called by the frame tags, or move it up and outside the frame tags.

    Comment

    • DruidWanderer
      New Member
      • Dec 2008
      • 3

      #3
      I'm pretty new at all this - most of that code was what I pillaged from several dissimilar scripts. Any chance you could show me how I would go about doing that?

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Put the code in the head and instead of using document.write, put a frame container there and set its src onload.

        Comment

        • DruidWanderer
          New Member
          • Dec 2008
          • 3

          #5
          Thanks acoder! That worked perfectly!

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Originally posted by DruidWanderer
            Thanks acoder!
            You're welcome :)
            Originally posted by DruidWanderer
            That worked perfectly!
            Glad it did! Post again if you have more questions.

            Comment

            Working...