Is there a standard copy-paste way to safely put a

2019-01-19 07:37发布

While embedding a SWF in HTML is not too hard, there are a few subtleties for different browsers, detecting if Flash is installed, etc. For enabling AJAX, there are standard chunks of code you can use to save the hassle of coping with all cases... is their a similar 'reference implementation' to embed a SWF which covers all the bases?

标签: html flash embed
5条回答
叼着烟拽天下
2楼-- · 2019-01-19 08:19

Is there a standard? Sadly no. The desirable points of a Flash embedding method are:

  1. modern browser compatible
  2. IE compatible
  3. ancient browser compatible
  4. standards-compliant
  5. supporting streamed Flash (play before the whole file is downloaded) in IE
  6. Don't Repeat Yourself
  7. allow fallback content
  8. no JavaScript reliance

but there is no one bunch of markup that satisfies all these points. Point 6 is impossible to achieve fully but some solutions fail worse than others.

About the simplest markup you can get away with is the version outlined in the classic Flash Satay article:

<object type="application/x-shockwave-flash" data="file.swf" width="x" height="y">
    <param name="movie" value="file.swf" />
    (Non-Flash content here)
</object>

The ALA article complains that this version won't prompt the user to download Flash if it isn't installed; personally I see this as a plus point. But it still fails on points 3 and 5. Point 5 may or may not matter: if your Flash file is a simple application, media player or loader stub it doesn't matter at all, but if it's a big animation it can be unfortunate.

Maybe point 3 doesn't matter any more; no-one's really using Netscape 4 or IE4 these days. But if it does to you, you need the old-school embed tag. This is also supported by modern browsers so that means you can use the ActiveX method for the outer object, so you get streaming in IE:

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="x" height="y">
    <param name="movie" value="file.swf" />
    <embed type="application/x-shockwave-flash" src="file.swf" width="x" height="y" />
</object>

This is the ‘traditional’ method of embedding Flash. It fails on points 4 and 7 and is slightly worse on point 6.

The third approach, used by libraries such as SWFObject is to use JavaScript to choose the best way to instantiate Flash on the current browser. This can hit the all the above points except, naturally, 8. Some libraries offer ways to mitigate that by also including static object markup, trading point 8 for point 6.

查看更多
萌系小妹纸
3楼-- · 2019-01-19 08:20

I would recommend SWF Object compared to all the other options because it produces Standards Compliant html and is really easy to setup.

查看更多
祖国的老花朵
4楼-- · 2019-01-19 08:21
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script> 
<div id="myvideo"></div>
<script type="text/javascript">
var params = { allowScriptAccess: "always" };
var atts = { id: "myplayerid1" };
swfobject.embedSWF("http://www.youtube.com/v/gRvUpoTT-Bo&hl=pt-br&fs=1&enablejsapi=1&playerapiid=myplayerid1&version=3", "myvideo", "425", "344", "8", null, null, params, atts);
</script>

This might be the easy way ..use js fiddle to test any code ... that helped me a lot to try many things

查看更多
爷的心禁止访问
5楼-- · 2019-01-19 08:26

Apple (Link for example)

Content that your plug-ins will view needs to be embedded within HTML. Most browsers do this with an EMBED tag, but others require the OBJECT tag. For maximum compatibility, you can tune your page to support both.

Adobe (Link for example)

The OBJECT tag is used by Internet Explorer on Windows and the EMBED is used by Netscape Navigator (Macintosh and Windows) and Internet Explorer (Macintosh) to direct the browser to load the Macromedia Flash Player. Internet Explorer on Windows uses an ActiveX control to play Macromedia Flash content while all other browser and platform combinations use the Netscape plugin technology to play Macromedia Flash content. This explains the need for two tags.

<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
       codebase="http://download.macromedia.com/pub/
                 shockwave/cabs/flash/swflash.cab#version=6,0,40,0"
          WIDTH="550"
         HEIGHT="400"
             id="myMovieName">
    <PARAM NAME=movie VALUE="myFlashMovie.swf">
    <PARAM NAME=quality VALUE=high>
    <PARAM NAME=bgcolor VALUE=#FFFFFF>
    <EMBED href="/support/flash/ts/documents/myFlashMovie.swf"
        quality=high
        bgcolor=#FFFFFF
          WIDTH="550"
         HEIGHT="400"
           NAME="myMovieName"
          ALIGN=""
           TYPE="application/x-shockwave-flash"
    PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">
    </EMBED>
</OBJECT>
查看更多
啃猪蹄的小仙女
6楼-- · 2019-01-19 08:35

Many implementations of Flash embedding seem to be based on SWFObject. Is this the kind of thing you are looking for? Edit: project is hosted here now

查看更多
登录 后发表回答