Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Help with random iFrame content

    I am using the following javascript, but am hoping to change it up a little to suit my needs (scroll down for my question):

    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=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'
    
    //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"
    
    //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>
    It works great for my purposes, except for one thing. I need to add in a LARGE amount of HTML pages for it to randomize, and want to avoid entering each in one by one and having to update it each time I change the HTML directory.

    Is it possible to point to a directory of files rather than the individual files themselves?

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by Boyo Web Design View Post
    It works great for my purposes, except for one thing. I need to add in a LARGE amount of HTML pages for it to randomize, and want to avoid entering each in one by one and having to update it each time I change the HTML directory.

    Is it possible to point to a directory of files rather than the individual files themselves?
    No. Not with Javascript. You must specify the actual files.
    You could do it using a server-side language such as PHP or ASP.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 05-28-2010 at 08:42 AM.


  •  

    Tags for this Thread

    Posting Permissions

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