: How can I neatly embed Flash in a page in a way that is cross-browser compatible? When I receive Flash objects from my designer, it comes with an example HTML page which includes both <object>
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?
More posts by @Hamaas447
4 Comments
Sorted by latest first Latest Oldest Best
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.
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.
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.
There are some great answers to this already over at StackOverflow: stackoverflow.com/questions/2254027/which-browsers-support-the-embed-and-object-tags
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.