Reputation: 227
I am trying to create this html elements dynamically on the onload of my page,however;when I run it the code wont work on IE8 but okay in firefox,safari,and others.
function getmovie() {
var container = document.getElementById("container");
if (!container)
return;
var object = document.createElement("object");
object.setAttribute("width", "512");
object.setAttribute("height", "296");
var param1 = document.createElement("param");
param1.setAttribute("name", "movie");
param1.setAttribute("value", "url");
var param2 = document.createElement("param");
param2.setAttribute("name", "allowFullScreen");
param2.setAttribute("value", "true");
var embed = document.createElement("embed");
embed.setAttribute("src", "my url");
embed.setAttribute("type", "application/x-shockwave-flash");
embed.setAttribute("allowFullScreen", "true");
embed.setAttribute("width", "512");
embed.setAttribute("height", "296");
object.appendChild(param1);
object.appendChild(param2);
object.appendChild(embed);
container.appendChild(object);
}
Can anyone correct my code?
Upvotes: 0
Views: 3400
Reputation: 63588
You can't set the name
attribute of ANY element in IE by using .setAttribute('name', value);
You will need to use:
param1.name = 'movie';//works
param1.setAttribute("name", "movie");//will fail
Note: this bug was fixed in IE8 (as long as you are running in IE8 Standards Mode)
Upvotes: 1
Reputation: 59451
Could this be the reason?
IE7 breaks getElementById
If that is not the case, try setting the codebase and classid attributes of the object tag object.
object.setAttribute("codebase", "http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab");
object.setAttribute("classid", "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000");
Upvotes: 0
Reputation: 38346
Unless you have a really good reason to build your Flash including DOM elements manually, consider replacing the code with a single call to a framework like SWFObject that does all the "dirty work" for you.
swfobject.embedSWF("flashmovie.swf", "container", "512", "296", "9.0.0",
"expressInstall.swf", { allowFullScreen : true });
Upvotes: 3