Tremend Tech Blog

"Software is a great combination between artistry and engineering. When you finally get done and get to appreciate what you have done it is like a part of yourself that you've put together." (Bill Gates)

Looking for software experts?

Need an expert advice on software development? Need consulting work done in time and at high standards? Tremend has the right solution for you.

We can provide expertise in:
  • high traffic and complex content website infrastructures
  • website development-advanced web programming with PHP, .NET, Java, Flash/Flex, Ajax

Our friends

Dynamically embed youtube videos on IE6 using innerHTML

August 6th, 2008 by Marius Hanganu

I got this annoying problem today: when trying to automatically populate a DIV with embed code from youtube, nothing happened on IE6. IE7 and FF work fine.

Some googling and I found this good resource about flash embedding techniques. There is one library that fixes the problem, called ufo.js, library which was far too big for my taste (11k uncompressed). So after some trimming, I was a bit surprised to find out that all that was needed to make your innerHTML code work with Internet Explorer 6, was the missing CLASSID attribute for the object tag.

Here is a link to a test page that works well an FF, IE7, IE6, Opera and Safari. There is one small reusable javascript function that fixes the embedded code by adding the CLASSID attribute to the object tag. After that, you can use innerHTML attribute to populate the contents of your HTML elements with embedded video code.

1
2
3
4
5
6
7
8
var fixEmbeddedVideo = function(embedCode) {
   if(embedCode && embedCode.toLowerCase().indexOf(’classid’) == -1) {
      var objPos = embedCode.toLowerCase().indexOf(’object ‘) + ‘object ‘.length;
      return embedCode.substr(0, objPos) + ‘classid=”clsid:D27CDB6E-AE6D-11cf-96B8-444553540000″ ‘ + embedCode.substr(objPos);
   } else {
      return embedCode;
   }
}

Blogged with Flock

Tags: , , , , ,

Share/Save

Posted in HTML, Javascript | 5 Comments »