# Loading random .swf's into .html document

**URL:** <https://forum.kirupa.com/t/loading-random-swfs-into-html-document/227380>\
**Category:** flash\
**Created:** [May 29, 2007, 7:53pm UTC](https://forum.kirupa.com/t/loading-random-swfs-into-html-document/227380 "2007-05-29T19:53:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![HuskerJay](https://avatars.discourse-cdn.com/v4/letter/h/8baadc/32.png) [@HuskerJay](https://forum.kirupa.com/u/HuskerJay)\
**Post date:** [May 29, 2007, 7:53pm UTC](https://forum.kirupa.com/t/loading-random-swfs-into-html-document/227380/1 "2007-05-29T19:53:57Z")

</div>

\*\*Desired outcome: \*\*  
When person goes to site ([http://www.jayminnickinteractive.com](http://www.jayminnickinteractive.com/)) they are presented with a different .swf file each time they visit or refresh the page - currently I have three different .swf files that can served up.

**What I’ve done so far to make this outcome a reality:**  
I included a javascript array in the .html document that selects one of three .swf files to present in the page. Here is the javascript:  
[COLOR=Olive]\<script language=“javascript”\>  
\<!–  
files = new Array();  
files[0] = “crayolas\_pre.swf”;  
files[1] = “ice\_cream\_pre.swf”;  
files[2] = “drinks\_pre.swf”;  
index = Math.floor(Math.random() \* files.length);  
movie = files[index];  
// now write out the object and embed tags replacing the filename with the variable movie  
document.write(’\<object classid=“clsid:D27CDB6E-AE6D-11cf-96B8-444553540000” codebase=“[http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0](http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0)” width=800 height=600\>’);  
document.write(’\<param name=movie value="’ + movie + ‘"\> \<param name=quality value=high\> \<param name=bgcolor value=#ffffff\> \<param name=“menu” value=“false”\>’);  
document.write(’\<embed src="’ + movie + ‘" quality=high bgcolor=#ffffff menu=false width=800 height=600 type=“application/x-shockwave-flash” pluginspage=“[http://www.macromedia.com/shockwave/download/index.cgi?P1\_Prod\_Version=ShockwaveFlash](http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash)”\>\</embed\>’);  
document.write(’\</object\>’);  
//–\>  
\</script\>[/COLOR]

**Problem:** This works fine if you are using Firefox, Safari, etc. HOWEVER, if you are using IE then the page is completely blank. I tried using a if IE conditional statement to serve up another .swf if the browser was IE, but that didn’t work either.  
Here’s the code for that as well:  
[COLOR=Olive]\<!–[if IE]\>  
\<object classid=“clsid:D27CDB6E-AE6D-11cf-96B8-444553540000” codebase=“[http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0](http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0)” width=“800” height=“600”\>  
\<param name=“movie” value=“drinks\_pre.swf” /\>  
\<param name=“quality” value=“high” /\>  
\<embed src=“drinks\_pre.swf” quality=“high” pluginspage=“[http://www.macromedia.com/go/getflashplayer](http://www.macromedia.com/go/getflashplayer)” type=“application/x-shockwave-flash” width=“800” height=“600”\>\</embed\>  
\</object\>  
\<script type=“text/javascript” src=“fixit.js”\>\</script\>  
\<![endif]–\>  
[/COLOR]
