# Loading an SWF via HTML Button (AJAX)

**URL:** <https://forum.kirupa.com/t/loading-an-swf-via-html-button-ajax/302805>\
**Category:** flash\
**Created:** [January 7, 2010, 6:37pm UTC](https://forum.kirupa.com/t/loading-an-swf-via-html-button-ajax/302805 "2010-01-07T18:37:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![zigsta](https://avatars.discourse-cdn.com/v4/letter/z/ed8c4c/32.png) [@zigsta](https://forum.kirupa.com/u/zigsta)\
**Post date:** [January 7, 2010, 6:37pm UTC](https://forum.kirupa.com/t/loading-an-swf-via-html-button-ajax/302805/1 "2010-01-07T18:37:00Z")

</div>

Hi there,

I have a html site with three div tags, I want to be able to load an SWF into one of the div’s via a html button.

I have looked into using AJAX and have this solution:  
[SIZE=1][COLOR=Blue]  
\<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “[http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd](http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd)”\>

\<html xmlns=“[http://www.w3.org/1999/xhtml](http://www.w3.org/1999/xhtml)”\>  
\<head\>  
\<meta http-equiv=“content-type” content=“text/html; charset=utf-8” /\>  
\<title\>Kristian Brace : Portfolio\</title\>  
\<meta name=“keywords” content="poplar farm, holiday cottages, last minuet deals, cheap holidays, somerset, weston super mare, holiday, cottages, " /\>  
\<meta name=“description” content=“Poplar Farm Holiday Cottages offer first class holidays in Somerset at competitive rates” /\>  
\<link href=“default.css” rel=“stylesheet” type=“text/css” /\>

\<script type=“text/javascript”\>

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

- Dynamic Ajax Content- © Dynamic Drive DHTML code library ([www.dynamicdrive.com](http://www.dynamicdrive.com))
- This notice MUST stay intact for legal use
- Visit Dynamic Drive at [http://www.dynamicdrive.com/](http://www.dynamicdrive.com/) for full source code  
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/

var bustcachevar=1 //bust potential caching of external pages after initial request? (1=yes, 0=no)  
var loadedobjects=""  
var rootdomain=“http://”+window.location.hostname  
var bustcacheparameter=""

function ajaxpage(url, containerid){  
var page\_request = false  
if (window.XMLHttpRequest) // if Mozilla, Safari etc  
page\_request = new XMLHttpRequest()  
else if (window.ActiveXObject){ // if IE  
try {  
page\_request = new ActiveXObject(“Msxml2.XMLHTTP”)  
}  
catch (e){  
try{  
page\_request = new ActiveXObject(“Microsoft.XMLHTTP”)  
}  
catch (e){}  
}  
}  
else  
return false  
page\_request.onreadystatechange=function(){  
loadpage(page\_request, containerid)  
}  
if (bustcachevar) //if bust caching of external page  
bustcacheparameter=(url.indexOf("?")!=-1)? “&”+new Date().getTime() : “?”+new Date().getTime()  
page\_request.open(‘GET’, url+bustcacheparameter, true)  
page\_request.send(null)  
}

function loadpage(page\_request, containerid){  
if (page\_request.readyState == 4 && (page\_request.status==200 || window.location.href.indexOf(“http”)==-1))  
document.getElementById(containerid).innerHTML=page\_request.responseText  
}

function loadobjs(){  
if (!document.getElementById)  
return  
for (i=0; i\<arguments.length; i++){  
var file=arguments\*  
var fileref=""  
if (loadedobjects.indexOf(file)==-1){ //Check to see if this object has not already been added to page before proceeding  
if (file.indexOf(".js")!=-1){ //If object is a js file  
fileref=document.createElement(‘script’)  
fileref.setAttribute(“type”,“text/javascript”);  
fileref.setAttribute(“src”, file);  
}  
else if (file.indexOf(".css")!=-1){ //If object is a css file  
fileref=document.createElement(“link”)  
fileref.setAttribute(“rel”, “stylesheet”);  
fileref.setAttribute(“type”, “text/css”);  
fileref.setAttribute(“href”, file);  
}  
}  
if (fileref!=""){  
document.getElementsByTagName(“head”).item(0).appendChild(fileref)  
loadedobjects+=file+" " //Remember this object as being already added to page  
}  
}  
}

\</script\>

\</head\>  
\<body\>

```
&lt;div id="menu"&gt;
    
    &lt;h2&gt;Kristian Brace&lt;/h2&gt;&lt;p&gt;

&lt;ul&gt;
    
    &lt;li&gt;&lt;a href="about.html"&gt;About&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="#"&gt;Projects&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="links.html"&gt;Links&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="contact.html"&gt;Contact&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

```

\</div\>

```
&lt;div id="header"&gt;
    &lt;h2&gt;Projects&lt;/h2&gt;&lt;p&gt;

&lt;ul&gt;
    &lt;a href="javascript:ajaxpage('mg_mediacom.swf', 'flash');"&gt;MediaCom 2&lt;/a&gt;

    &lt;li&gt;&lt;a href="#"&gt;MediaCom&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;Short & Suite&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;British Red Cross&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;poplar Farm&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;VTKTM&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="guestbook.html"&gt;aniMate&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="contact.html"&gt;Hansel & Gretel&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;Foursight&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;Timelapse&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;3D Showreel&lt;/a&gt;&lt;/li&gt;
    &lt;li&gt;&lt;a href="cottages.html"&gt;The Iron Man&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

```

\</div\>

```
&lt;div id="content"&gt;

    &lt;h2&gt;Mediacom&lt;/h2&gt;&lt;p&gt;
    &lt;a href="javascript:ajaxpage('mg_mediacom.swf', 'flash');"&gt;MediaCom 3&lt;/a&gt;
&lt;div id="flash"&gt;

&lt;/div&gt;
    
    
    &lt;p&gt;MediaCom&lt;/p&gt;

    &lt;p&gt;This is a description of the flash movie playing above.&lt;/p&gt;

```

\</div\>

\<div id=“footer”\>

```
&lt;p id="legal"&gt;Copyright &copy; 2009 . All Rights Reserved.&lt;/p&gt;

```

\</div\>

\</body\>  
\</html\>  
[/COLOR][/SIZE]

When the html button is clicked it loads but displays a mass of nonsense code.

does anybody have any ideas or experience with loading swf from html

Thanks
