How to embed a SWF file in an HTML page?
Solution 1
The best approach to embed a SWF into an HTML page is to use SWFObject.
It is a simple open-source JavaScript library that is easy-to-use and standards-friendly method to embed Flash content.
It also offers Flash player version detection. If the user does not have the version of Flash required or has JavaScript disabled, they will see an alternate content. You can also use this library to trigger a Flash player upgrade. Once the user has upgraded, they will be redirected back to the page.
An example from the documentation:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>SWFObject dynamic embed - step 3</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0");
</script>
</head>
<body>
<div id="myContent">
<p>Alternative content</p>
</div>
</body>
</html>
A good tool to use along with this is the SWFObject HTML and JavaScript generator. It basically generates the HTML and JavaScript you need to embed the Flash using SWFObject. Comes with a very simple UI for you to input your parameters.
It Is highly recommended and very simple to use.
Solution 2
<object width="100" height="100">
<param name="movie" value="file.swf">
<embed src="file.swf" width="100" height="100">
</embed>
</object>
Solution 3
How about simple HTML5 tag embed?
<!DOCTYPE html>
<html>
<body>
<embed src="anim.swf">
</body>
</html>
Solution 4
This is suitable for application from root environment.
<object type="application/x-shockwave-flash" data="/dir/application.swf"
id="applicationID" style="margin:0 10px;width:auto;height:auto;">
<param name="movie" value="/dir/application.swf" />
<param name="wmode" value="transparent" /> <!-- Or opaque, etc. -->
<!-- ↓ Required paramter or not, depends on application -->
<param name="FlashVars" value="" />
<param name="quality" value="high" />
<param name="menu" value="false" />
</object>
Additional parameters should be/can be added which depends on .swf it self. No embed, just object and parameters within, so, it remains valid, working and usable everywhere, it doesn't matter which !DOCTYPE is all about. :)
Solution 5
If you are using one of those js libraries to insert Flash, I suggest adding plain object embed tag inside of <noscript/>
.
Related videos on Youtube

Comments
-
MetaGuru about 2 years
How do you embed a SWF file in an HTML page?
-
Anheledir about 14 yearsThat code isn't XHTML-valid ... <embed> must not be within a object-tag.
-
Anheledir about 14 yearsThe "click to activate" problem is called "eolas activation" but is removed in actual versions of the IE.
-
Ólafur Waage about 14 yearsNo specification of the user to be XHTML valid, he asked for HTML
-
Ardee Aram over 11 yearsSWFObject is good. It simply works. An even more wonderful idea is to use a Content Delivery Network to get the javascript. I use Google's ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js
-
AndyMcKenna about 10 yearsI had problems with using the object tag directly with IE9 but it works perfectly with swfobject.
-
Spooky about 10 yearsNote that object>data and movie>value parameters are the same. This code should work for any free to watch and share - youtube video.
-
KRyan about 10 yearsGenerally speaking, it's desirable for answers to explain the code they give, rather than just dropping code on the asker. The goal is to learn about problems and prevent them in the future rather than make them vanish.
-
Joko Wandiro almost 9 yearsthis article have a good explanation about embedding flash and valid XHTML. yoast.com/articles/valid-flash-embedding
-
Sumit Ramteke almost 9 yearsThanks for your answer. Now can you suggest a player as well for accessing playback capability along with working example in html itself. ????
-
Barkermn01 almost 9 yearsfor google @Stoic sorry your wrong it should be
//www...
using//
means that if your on HTTPS or HTTP it works using the same connection type -
rorypicko over 8 years-1 swfobject isn't just part of JavaScript, you can't just call it without embedding the library. and most of the functionality for the <object> tag has been stripped out from HTML 4 to 5. It can still be used, but not recommended. All in all a very bad answer.
-
Allan over 8 yearsdid you already tried it before saying its a very bad answer? keep in mind that very bad answer, is the answer that don't totally work or wrong.
-
rorypicko over 8 yearsthe fact that you're informing someone to use javascript, and then pasting code using a javascript library that you haven't even mentioned makes it a bad answer
-
Allan over 8 yearsI already mentioned to used Javascript and gave the script. If I gave the whole working code/script that makes a spoonfeeding. The script is fine its only a logic.
-
rorypicko over 8 yearsYou're misunderstanding my comment. You haven't told him to include the SWFObject Javascript file
-
vladkras almost 8 yearswhy not use
data
attribute in <object> element? Quote from w3c html5 docs: At least one of either the data attribute or the type attribute must be present. -
Mohammed Javed about 7 yearsCan this is work on that system where flash player is not install or it support all browsers.
-
Lucky about 6 yearsThe project is now moved to GitHub: github.com/swfobject/swfobject and the new technique to embed swf object is
var el = document.getElementById("my-target-element"); swfobject.embedSWF("myContent.swf", el, 300, 120, 10);
-
Chris almost 6 yearsswfobject no longer works properly with Chrome. Chrome new policy (HTML by default) is unrolled starting at version 55 and no longer initializes the variables that swfobject needs to test if Flash is installed. swfobject may give an incorrect message 'install flash' when in reality Flash is simply being blocked by Chrome, causing confusion for the user. For Chrome, the best course of action may be to simply use <object> to embed Flash.
-
joshuakcockrell about 4 yearsNote: This answer is over 10 years old and very out of date. This doesn't play nicely with Chrome anymore as @Chris mentions. Please see some of the much better HTML5 answers. They are simple and supported directly by browser vendors and don't require downloading the swfobject library for your users.
-
Hermann.Gruber over 3 years@JokoWandiro the link your provided is unfortunately gone. Here's an archived version: https://yoast.com/…