Women in Technology

Hear us Roar



Article:
  Hi-Res YouTube Hacks
Subject:   Browser Compatibility
Date:   2008-08-19 17:09:32
From:   Mannni
Response to: Browser Compatibility

You need to use document.write to make this work on IE6.


Either rewrite the function so that you can place it in the document flow directly where the video should appear, or dynamically create an iframe with its src linked to an empty HTML document (containing <html><body></body></html>) on the same domain; then you can document.write to it anytime.
Uhm... sorry, that might sound complicated, a little bit slower:
To replace a YT embedded object with your code:
1. Create an iframe object using document.createElement.
1.5 Set the iframe's src to emptyhtmldoc.html (as described above).
2. Fetch the old embed code from the DOM and modify it as you need it.
3. Delete the old code from the document.
4. Hook in your iframe there.
5. document.write the modified object code to the iframe (document.getElementById('iframeid').contentWindow.document.write(newhtml)). Don't set innerHTML or DOM methods as this would again knock IE6 out :) .


I have written scripts using this method many times (actually started with it to prevent IE6's "Click to activate" pain from appearing), it works in every browser, even in crappy IE 5.0. The only not-so-optimal issue with it is that you need this empty document sitting on your server; without it, you couldn't access the document in the iframe due to cross-site scripting restrictions.


Every serious JS developer MUST make his scripts working on IE6 as IE6 still has a big market share and will only slowly disappear. You can install all relevant IE versions i.e. using this: http://tredosoft.com/Multiple_IE , or using VMware.