Results 1 to 3 of 3

Thread: Random iframe not so random

  1. #1
    Join Date
    Jul 2008
    Location
    Pittsburgh, PA, USA
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Random iframe not so random

    1) Script Title: random iframe content

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...ndomiframe.htm

    3) Describe problem: Instead of picking one of my included files randomly, it just goes with the second one. Here is my code:

    <script language="JavaScript1.2">

    //Random iframe content- © Dynamic Drive (www.dynamicdrive.com)
    //For full source code, and Terms Of use, visit http://dynamicdrive.com
    //This credit MUST stay intact for use

    var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
    var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

    //Specify IFRAME display attributes
    var iframeprops='width=380 height=430 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"'

    //Specify random URLs to display inside iframe
    var randomcontent=new Array()
    randomcontent[0]="http://www.randyschreiber.com/random1.html"
    randomcontent[0]="http://www.randyschreiber.com/random2.html"


    //No need to edit after here
    if (ie||dom)
    document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')

    function random_iframe(){
    if (ie||dom){
    var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
    iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
    }
    }

    window.onload=random_iframe

    </script>

    Thanks for taking a look, any ideas what's wrong?

    ~Bistromath

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    At the top of your script find this:
    Code:
    randomcontent[0]="http://www.randyschreiber.com/random1.html"
    randomcontent[0]="http://www.randyschreiber.com/random2.html"
    The code only sees one page. randomcontent[0] will only overlap. You have to increase the numbers as you go along, try this:
    Code:
    randomcontent[0]="http://www.randyschreiber.com/random1.html"
    randomcontent[1]="http://www.randyschreiber.com/random2.html"
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2008
    Location
    Pittsburgh, PA, USA
    Posts
    26
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    great nile, thanks for the reply!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •