Load flash from JavaScript with Object Tag

1.3k Views Asked by At

I tried to load flash (swf file) either from external sources or local sources,

I use object tag in html to contain the flash for some reason, if I load the flash directly in the object tag, it will work flawlessly, like this:

<object height="100" width="100" data="helloworld.swf" id="flash"></object>

Next, I need to load the flash dynamically from JavaScript, but several problems arise:

var flash=document.getElementById("flash");
flash.setAttribute("data","helloworld.swf");

the code above works fine in Chrome, but it doesn't do anything in IE (my IE is IE11 on windows 8)

If I modify the object tag to iframe tag, then it works, but I need it to be object tag,

Any solutions come to mind?

2

There are 2 best solutions below

0
On

Use SWFObject. It will save you from all the cross-browser compatibility troubles.

0
On

You can force the refresh by readding the object:

var flash = document.getElementById("flash");
flash.setAttribute("data","helloworld.swf");

var clone = flash.cloneNode(true);
flash.parentNode.replaceChild(clone, flash);