4 iframes randomising content (URLs)

benreynolds4

New Member
4 iframes randomising content (URLs)

hi all. i would like these four iframes to randomise on refresh (or even by a button press) from a list of URLs I set.
It would be cool if it was a javascript.

here's the code

</html>
<head>
<title>Untitled Document</title>
</head>

<style type="text/css">
html, body, div, iframe { margin:0; padding:0; height:100%; }
iframe { display:block; width:50%; height:50%; border:0; }
</style>

<body marginheight="0" marginwidth="0">

<iframe src="http://www.yahoo.com/" width="50%" height="50%" frameborder="none" align="left">
</iframe>

<iframe src="http://www.nytimes.com/" width="50%" height="50%" frameborder="none" align="top" align="right">
</iframe>

<iframe src="http://www.youtube.com/" width="50%" height="50%" frameborder="none" align="right">
</iframe>

<iframe src="http://www.google.com/webhp?hl=en" width="50%" height="50%" frameborder="none" align="bottom">
</iframe>

</body>



</html>



any ideas....

thanks

ben
 

jnjc

New Member
The code below does what you want (I had to replace the url http://www.nytimes.com it seemed to stuff things up), you can see it working at :

http://www.solasit.com.au/sandbox/webdesign/randomUrl.htm

Code:
<iframe id="frm1" width="50%" height="50%" frameborder="none" align="left">
</iframe>

<iframe  id="frm2" width="50%" height="50%" frameborder="none" style="float:right">
</iframe>

<iframe  id="frm3" width="50%" height="50%" frameborder="none" align="left">
</iframe>

<iframe id="frm4" width="50%" height="50%" frameborder="none" style="float:right">
</iframe>

<script type="text/javascript">
var url=new Array();
url[0] = "http://www.yahoo.com/";
url[1] = "http://www.solasit.com.au";
url[2] = "http://www.youtube.com/";
url[3] =  src="http://www.google.com/webhp?hl=en";
var dirty=new Array();
dirty[0] = null;
dirty[1] = null;
dirty[2] = null;
dirty[3] = null;
for (i=1;i<=4;i=i+1)  {
    el = document.getElementById("frm" + i);
    var exitloop = false;	
    while (exitloop == false) {
        frm = Math.floor(Math.random()*4);
        if (dirty[frm] == null) {
             dirty[frm] = url[frm];
	     el.src = url[frm];
	     exitloop = true;
        }
    }
}
</script>
 
Last edited:
Top