FlashObject and Frames
Microsoft is finally going to patch IE so it doesn’t infringe on the Eolas patent portfolio. Of course that means we need to update all of our plug-in code so we don’t confuse users. The quickest solution is to use deconcept’s FlashObject. I’ve been using it a lot lately and it’s awesome.
FlashObject works by dynamically creating the flash plug-in code and replacing the html located within a specified tag. However, this presents a problem when you’re sharing code between pages in different frames. FlashObject is only looking on the page that loaded it for that specified tag. Of course you could always include the flashobject.js on each page, but that just seems like a waste to me.
The quickest and easiest solution for me was to modify the write method of FlashObject. Instead of just passing in the tag to be replaced, I also pass in a reference of the document where the tag is located. The new way of calling FlashObject’s write method looks like this:
fo.write(“flashcontent”,document);
Using the keyword document references the current document, but you can easily change that to what ever you need. Then in the flashobject.js file I changed the following lines:
write: function(elementId){
...
var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
to
write: function(elementId, targetDoc){
...
var n = (typeof elementId == 'string') ? targetDoc.getElementById(elementId) : elementId;
Now I can load the library once and have multiple frames use it. I'm pretty sure this method will work for popup windows too.
Note: I haven’t tested this solution thoroughly and I’m sure there is a better way of doing it to, but it works for now.