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 - © 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.
Bookmarks