Jump to content

Adding embed tag to DOM problems in IE?


grippat

Recommended Posts

I have a little bit of JavaScript that's run when a user clicks on an image. This code makes the image div invisible and creates object, param, and embed tags to insert an .swf file in it's place. This all works fine in Firefox of course but IE throws an "Invalid argument" error on this line: "flashObjTag.appendChild(flashEmbedTag);". Any ideas? Here's the full code...

      var imgUrl = document.getElementById('testImg').src;      var flashUrl = imgUrl.replace(/images/, 'swfs');      flashUrl = flashUrl.replace(/jpg/, 'swf');            // Hide the static image      document.getElementById('testImg').style.display = "none";            // Build and insert Flash element on the page.      var flashObjTag = document.createElement('object');      flashObjTag.id = 'animation';      flashObjTag.width = '320';      flashObjTag.height ='240';      flashObjTag.style.zIndex = '-5';            var flashParamTag1 = document.createElement('param');      flashParamTag1.name = 'movie';      flashParamTag1.value = flashUrl;            var flashParamTag2 = document.createElement('param');      flashParamTag2.name = 'wmode';      flashParamTag2.svalue = 'transparent';           var flashEmbedTag = document.createElement('embed');      flashEmbedTag.src = flashUrl;      flashEmbedTag.width = '320';      flashEmbedTag.height = '240';      flashEmbedTag.wmode = 'transparent';            flashObjTag.appendChild(flashParamTag1);      flashObjTag.appendChild(flashParamTag2);      flashObjTag.appendChild(flashEmbedTag);              var mainImg = document.getElementById('mainImg');      mainImg.appendChild(flashObjTag);

Link to comment
Share on other sites

If a browser doesn't have a certain element defined then it would probably throw an error if you try to create and append it. You can either use innerHTML, or detect which browser it is and only show either the embed or the object.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...