0

I am trying to display some html embedding a SWF object using javascript.

The script works fine without the SWF object. Howevever, when the object is included in the html inserted into the div the script no longer runs.

If anyone can suggest fix or spot error, I would greatly appreciate it.

Here is jsfiddle.

http://jsfiddle.net/UJpQ4/

Code (same as jsfiddle):

html:

<a href="javascript:void(0)" onclick="takeProfilePic('0');">Show Flash</a>
<a href="javascript:void(0)" onclick="takeProfilePic('1');">Do not show flash</a>
<tr><td colspan=2 align="center"><div id="takepic"></div>

javascript:

function takeProfilePic(type) {
//   alert(type);
if (type==0)
  {
   var target = 'takepic';
   var photo = '<tr><td colspan=2 align="center">hello</td></tr>';
document.getElementById(target).innerHTML = photo;
return false;
  }
    else if (type==1) {
        var target = 'takepic';
   var photo = '<tr><td colspan=2 align="center"><a href="stepthree.php"><img src="images/collapse.gif" border=0></a></td></tr><tr><td colspan=2 align="center">NO FLASH OBJECT HERE</td></tr>';
  document.getElementById(target).innerHTML = photo;
return false;      
    }     
}
user1260310
  • 2,229
  • 9
  • 49
  • 67
  • In the future, please include all relevant code in your post and **don't** just include a link to jsFiddle. Your post should stand alone from any other resource; consider what'd happen if jsFiddle went down in the future. – bfavaretto Aug 12 '12 at 20:59
  • 1
    Your embed code is wrong. Consider using [swfobject](http://code.google.com/p/swfobject/) for easy, reliable swf ebedding from javascript. – bfavaretto Aug 12 '12 at 21:04
  • Good point, bfavaretto. Code now in question. If you don't mind my asking, what is the error in the embed code? – user1260310 Aug 13 '12 at 00:58
  • Sorry, my comment was not accurate. I was referring to this: ``. It may not work on all browsers (and it's missing ``). But I don't see any erros on your jsfiddle (where the swf obviously won't load), and the script continues to work there (you can alternate between flash and no-flash at any time). – bfavaretto Aug 13 '12 at 01:07

1 Answers1

1

Use EMBED tag instead of OBJECT tag.

function takeProfilePic(type) {
//   alert(type);
if (type==0)
  {
   var target = 'takepic';
   var photo = '<tr><td colspan=2 align="center"><a href="stepthree.php"><img src="images/collapse.gif" border=0></a></td></tr><tr><td colspan=2 align="center"><div id="piccontent"><embed src="file.swf" type="application/x-shockwave-flash" width="520" height="400" /></div></td></tr>';
   document.getElementById(target).innerHTML = photo;
   return false;
  }
  else if (type==1) {
   var target = 'takepic';
   var photo = '<tr><td colspan=2 align="center"><a href="stepthree.php"><img src="images/collapse.gif" border=0></a></td></tr><tr><td colspan=2 align="center"><div id="piccontent">NO FLASH OBJECT HERE</div></td></tr>';
   document.getElementById(target).innerHTML = photo;
   return false;      
  }     
}
Jay
  • 4,627
  • 1
  • 21
  • 30
  • could not get this to work. Can you show it working in jsfiddle? – user1260310 Aug 13 '12 at 12:57
  • Here's the updated [jsfiddle](http://jsfiddle.net/UJpQ4/11/). Note that the plugin will never run inside jsfiddle because the SWF URL will point to jsfiddle server. Make sure you don't change anything that may interfere with the code. When run locally, put the `file.swf` in same folder as the HTML, or change the SWF URL (basic stuff). – Jay Aug 14 '12 at 03:29
  • Thanks. It works. If embed is what you use, why do most tutorials have object and embed. Also, is it advisable to include classid, codebase and all that other stuff they usually throw in? Does that do anything useful? Many thanks – user1260310 Aug 16 '12 at 14:31
  • AFAIK, `OBJECT` tag is originally a Microsoft extension for HTML, so not all browsers support it. It's only recently made as web standard in HTML 4.0. `CLASSID` attribute is required for ActiveX based object. `CODEBASE` is for specifying the base URL of relative URL used (see more in [HTML4 specs](http://www.w3.org/TR/1999/REC-html401-19991224/)). – Jay Aug 16 '12 at 15:09