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;      
    }     
}
4
  • 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. Commented Aug 12, 2012 at 20:59
  • 1
    Your embed code is wrong. Consider using swfobject for easy, reliable swf ebedding from javascript. Commented Aug 12, 2012 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? Commented Aug 13, 2012 at 0:58
  • Sorry, my comment was not accurate. I was referring to this: <object data="file.swf" type="application/x-shockwave-flash" width="520" height="400">. It may not work on all browsers (and it's missing </object>). 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). Commented Aug 13, 2012 at 1:07

1 Answer 1

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;      
  }     
}
Sign up to request clarification or add additional context in comments.

4 Comments

could not get this to work. Can you show it working in jsfiddle?
Here's the updated jsfiddle. 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).
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
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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.