Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-28-2010, 08:06 AM   PM User | #1
Boyo Web Design
New to the CF scene

 
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Boyo Web Design is an unknown quantity at this point
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!
Boyo Web Design is offline   Reply With Quote
Old 05-28-2010, 08:22 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
directory, html, iframe, large, random

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:26 PM.


Advertisement
Log in to turn off these ads.