View Full Version : Random iframe

11-21-2012, 10:33 PM

I got this script online which is meant to display random iframes onload. This script works for me locally, however when uploading and testing online it does not work. It displays absolutely nothing. I tested this with Firefox and IE.

I'm an amateur with Javascript so if someone could spot why this is happening that would be awesome!


<script language="JavaScript1.2">

var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

var iframeprops='width=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'

var randomcontent=new Array()

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


Old Pedant
11-21-2012, 11:09 PM
Um...that script is ancient history.

It's pretty much as obsolete as you can get.

Let's rewrite it...

<!DOCTYPE html>
Here is some stuff not in the iframe.<br/><br/>
Here is some stuff not in the iframe.<br/><br/>
Here is some stuff not in the iframe.<br/><br/>
Here is some stuff not in the iframe.<br/><br/>

<iframe id="dynstuff" width="100%" height="130" marginwidth="0" marginheight="0"
hspace="0" vspace="0" frameborder="1" scrolling="no">

<script type="text/javascript">
function( )
var randomcontent = [

var theFrame = document.getElementById("dynstuff");

var which = Math.floor( Math.random() * randomcontent.length );

theFrame.src = randomcontent[which];

I did just realize that if you didn't upload all those "randomX.html" pages to your online site the code would never have worked. Could that have been the problem? Still, that code was so ancient as to need to be buried.

11-22-2012, 01:18 PM
That worked well, thanks!

I did have the relevant pages uploaded with the old script but it wasn't working. Now that you mention that the script is prehistoric it makes sense!

It's funny, I'm pretty savvy with Actionscript and I couldn't figure out what the problem with the Javascript was.

Anyway, thanks again for your help.