Results 1 to 5 of 5

Thread: Help with Random iframe content

  1. #1
    Join Date
    Mar 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with Random iframe content

    1) Script Title: Random iframe content

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

    3) Describe problem:
    I would like to use this script many times on the same page. I've been playing around with it a bit but can't seem to get it to work.

    I've changed the iframe id="dynstuff" to something unique for each place I use it... but it still isn't working.

    I hope there is an easy/quick way to accomplish this.

    Thanks,
    ~D

  2. #2
    Join Date
    Mar 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yeeep!

    I just read this thread: http://www.dynamicdrive.com/forums/showthread.php?t=320

    If anyone can offer me any help I would greatly appreciate it... If it is going to be super time consuming then dont worry.

    Thanks,
    ~D

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    This is actually one of the easy ones:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    
    //Random iframes content - &#169; Dynamic Drive (www.dynamicdrive.com)
    //For full source code, and Terms Of use, visit http://dynamicdrive.com
    //This credit MUST stay intact for legal use
    //Updated in http://dynamicdrive.com/forums for multiple use by:
    //John Davenport Scheuer (username:jscheuer1)
    
    
    //Specify random URLs to display inside iframe
    var randomcontent=new Array()
    randomcontent[0]="random1.htm"
    randomcontent[1]="random2.htm"
    randomcontent[2]="random3.htm"
    randomcontent[3]="random4.htm"
    //Specify this IFRAME's display attributes
    randomcontent.iframeprops='width=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'
    
    //Specify random URLs to display inside another iframe (add as many of these as you want)
    var randomcontent2=new Array()
    randomcontent2[0]="random5.htm"
    randomcontent2[1]="random6.htm"
    randomcontent2[2]="random7.htm"
    randomcontent2[3]="random8.htm"
    //Specify this IFRAME's display attributes
    randomcontent2.iframeprops='width=300 height=250 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="auto"'
    
    //No need to edit after here
    function random_iframe(){
    if (!document.all&&!document.getElementById)
    return;
    this.content=arguments[0];
    random_iframe.num=random_iframe.num? random_iframe.num+1 : 1;
    this.frame_id='dynstuff'+random_iframe.num;
    document.write('<iframe id="'+this.frame_id+'" src="" '+this.content.iframeprops+'></iframe>');
    this.frame=document.getElementById? document.getElementById(this.frame_id) : document.all[this.frame_id];
    var cacheobj=this;
    this.onloadfunc=function(){
    cacheobj.frame.src=cacheobj.content[Math.floor(Math.random()*cacheobj.content.length)]
    };
    if ( typeof window.addEventListener != "undefined" )
        window.addEventListener( "load", this.onloadfunc, false );
    else if ( typeof window.attachEvent != "undefined" )
        window.attachEvent( "onload", this.onloadfunc );
    else {
        if ( window.onload != null ) {
            var oldOnload = window.onload;
            window.onload = function ( e ) {
                oldOnload( e );
                cacheobj.onloadfunc();
            };
        }
        else
            window.onload = this.onloadfunc;
    }
    }
    
    </script>
    
    </head>
    <body>
    <script type="text/javascript">
    new random_iframe(randomcontent)
    </script><br>
    <script type="text/javascript">
    new random_iframe(randomcontent2)
    </script><br>
    </body>
    </html>
    Notes: The main script now goes in the head. There is a different order for the array and frame properties and slightly different format for defining the iframe properties. Each iframe is called with a small script in the body. If you like, you can define just one set of pages (array) and its iframe properties and use it over and over again in the body of the page.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Mar 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Perfect!

    Works like a charm.
    Thank you so much. I really appreciate it.

    ~D

  5. #5
    Join Date
    Jul 2008
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    THANKS! I needed this too! I'm so happy!

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
  •