Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

When I receive Flash objects from my designer, it comes with an example HTML page which includes both <object> tags and <embed> tags as well as a whole heap of JavaScript. If I copy and paste this code in to my webpage, it works, but the code looks a mess (and there is so much of it!). If I remove the extra code and try either just <embed> or <object> on their own, it works in some browsers, but not others.

Is there a neat, minimal method that works in all the major browsers?

share|improve this question
1  
Might want to try StackOverflow, better answers can be found there for this question. –  Thorn007 Jul 9 '10 at 15:41
    
Fair point - an SO search has revealed this question: stackoverflow.com/questions/2254027/… However, I would imagine that most webmasters asking this questions would come here first, rather than StackOverflow, so I will self-answer with a link to the SO question. –  Mark Hatton Jul 9 '10 at 16:09
add comment

4 Answers 4

up vote 4 down vote accepted

SWFObject is what you're looking for. It's a JavaScript library that does all the cross-browser heavy-lifting. Simply include the JavaScript file in your page, create an element to be replaced in your source, and tell swfobject the name that that element and the path to the .swf file.

It does the rest.

<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
    /* path, replacement element, width, height, minimum flash version */
    swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>

That's all you need. Well, that and an element (usually a div) with an id="myContent" on it. The element with that ID will be replaced with whatever embed tag setup your current browser prefers.

The documentation is awesome, you'll have it up and running in no time. And if you hit any snags, ask another question.

share|improve this answer
add comment

There are some great answers to this already over at StackOverflow: http://stackoverflow.com/questions/2254027/which-browsers-support-the-embed-and-object-tags

share|improve this answer
add comment

You may want to have a look at Flash Satay - it is dated, but it quite nicely shows the issues in getting Flash working in a cross-browser fashion.

share|improve this answer
add comment

You can use one of the following resources:

Flash Embedding Cage Match - discusses the issues in detail and suggests some workarounds along with their pros and cons.

swfobject library [recommended] - draws inspiration from the above article and adds functionality which the above article left as an exercise.

SWFObject 2 HTML and JavaScript generator - is a wizard which generates swfobject markup (HTML and JavaScript). You can ditch swfobject by choosing "static publishing", the remove all JavaScript tags from the generated markup.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.