html中嵌入swf文件的幾種方法


轉自:http://blog.163.com/yuki_1154/blog/static/7120277120126109315935/

找了很久終於找到一個比較全面的:

1. object + embed       傳統的方法

優點:瀏覽器兼容性好,是 Macromedia 一直以來的官方方法
缺點:
a.embed 標簽是不符合 W3C 的規范的,無法通過驗證。當然,如果你不在乎什么規范不規范,另當別論。
b. 微軟由於種種原因,在 sp2 后限制了 IE 的 ActiveX 的使用模式,就是在頁面中的 ActiveX 有一個虛框,需要用戶點擊一次才能正常交互。Flash是作為一個 ActiveX 嵌入到網頁中的,所以它也會受牽連,只有通過 JS 嵌入 Flash 才能解決這個問題。
c.沒有 Flash 版本檢測,如果版本瀏覽器的flash插件版本不夠,或者不能正常顯示你的 swf 文件,或者會彈出一個 ActiveX 的確認安裝的框。

<object id="forfun" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300"
    codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">
    <param name="movie" value="/seufld/seufld/flash/focus2.swf">
    <param name="quality" value="high">
    <param name="bgcolor" value="#F0F0F0">
    <param name="menu" value="false">
    <param name="wmode" value="opaque"><!--Window|Opaque|Transparent-->
    <param name="FlashVars" value="">
    <param name="allowScriptAccess" value="sameDomain">
    <embed id="forfunex" src="/seufld/seufld/flash/focus2.swf"
        width="400"
        height="300"
        align="middle"
        quality="high"
        bgcolor="#f0fff8"
        menu="false"<!--添加后,ff下才正常-->
        play="true"
        loop="false"
        FlashVars=""
        allowScriptAccess="sameDomain"
        type="application/x-shockwave-flash"
        pluginspage="http://www.adobe.com/go/getflashplayer">
    </embed>
</object>

================分割線================

2. 單object

這種方法的名字叫做 Flash satay,最早是2002年由 Drew McLellan 發表在 A List Apart 上,后來又經過了幾次完善:
<object type="application/x-shockwave-flash" data="c.swf?path=movie.swf"
width="400" height="300">
<param name="movie" value="c.swf?path=movie.swf" />
<img src="http://xuguangzhi2003.blog.163.com/blog/noflash.gif" width="200" height="100" alt="" />
</object>

優點:這方法沒有embed,可以通過驗證,瀏覽器兼容性也不錯
缺點:
a.需要一個 holder swf 來加載你的目標 swf 以保證 IE 中的 stream 能力,如果你需要通過 flashvars 來傳參,或者和頁面的 JS 交互,會很麻煩。
b.ActiveX的虛框問題。
c.沒有版本檢測。
d.還是有少數用戶代理(比如一些版本的 safari 和一些屏幕閱讀器)不認這種方式,有 bug。 

================分割線================

3. 雙object

<object id="exercises" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="214" height="144">
    <param name="movie" value="${contextPath}/flex/photo.swf" />
    <param name="wmode" value="window" />
    <param name="flashvars" value=""/>
    <!--[if !IE]><!-->
    <object id="exercisesEx" type="application/x-shockwave-flash"
        data="${contextPath}/flex/photo.swf" width="214" height="144">
        <param name="flashvars" value=""/>
    <!--<![endif]-->
        <!--[if gte IE 6]>
        <![endif]-->
        <!--[if !IE]><!-->
        <!--<![endif]-->
        <a href="http://www.adobe.com/go/getflashplayer">
            <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
        </a>
    <!--[if !IE]><!-->
    </object>
    <!--<![endif]-->
</object>

================分割線================

4. flex提供的標准方法

<!-- BEGIN Browser History required section -->
<link rel="stylesheet" type="text/css" href="http://xuguangzhi2003.blog.163.com/blog/history/history.css" />
<!-- END Browser History required section -->

<script src="http://xuguangzhi2003.blog.163.com/blog/AC_OETags.js" language="javascript"></script>

<!-- BEGIN Browser History required section -->
<script src="http://xuguangzhi2003.blog.163.com/blog/history/history.js" language="javascript"></script>
<!-- END Browser History required section -->

<style>
body { margin: 0px; overflow:hidden }
</style>
<script language="JavaScript" type="text/javascript">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 60;
// -----------------------------------------------------------------------------
// -->
</script>
</head>

<body scroll="no">
<script language="JavaScript" type="text/javascript">
<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if ( hasProductInstall && !hasRequestedVersion ) {
    // DO NOT MODIFY THE FOLLOWING FOUR LINES
    // Location visited after installation is complete if installation is required
    var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
    var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

    AC_FL_RunContent(
        "src", "playerProductInstall",
        "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
        "width", "100%",
        "height", "100%",
        "align", "middle",
        "id", "ManagePlatform",
        "quality", "high",
        "bgcolor", "#869ca7",
        "name", "ManagePlatform",
        "allowScriptAccess","sameDomain",
        "type", "application/x-shockwave-flash",
        "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );
} else if (hasRequestedVersion) {
    // if we've detected an acceptable version
    // embed the Flash Content SWF when all tests are passed
    AC_FL_RunContent(
            "src", "ManagePlatform",
            "width", "100%",
            "height", "100%",
            "align", "middle",
            "id", "ManagePlatform",
            "quality", "high",
            "bgcolor", "#869ca7",
            "name", "ManagePlatform",
            "allowScriptAccess","sameDomain",
            "type", "application/x-shockwave-flash",
            "pluginspage", "http://www.adobe.com/go/getflashplayer"
    );
} else { // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be placed here. '
    + 'This content requires the Adobe Flash Player. '
       + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent); // insert non-flash content
}
// -->
</script>
<noscript>
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
            id="ManagePlatform" width="100%" height="100%"
            codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
            <param name="movie" value="ManagePlatform.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#869ca7" />
            <param name="allowScriptAccess" value="sameDomain" />
            <embed src="http://xuguangzhi2003.blog.163.com/blog/ManagePlatform.swf" quality="high" bgcolor="#869ca7"
                width="100%" height="100%" name="ManagePlatform" align="middle"
                play="true"
                loop="false"
                quality="high"
                allowScriptAccess="sameDomain"
                type="application/x-shockwave-flash"
                pluginspage="http://www.adobe.com/go/getflashplayer">
            </embed>
    </object>
</noscript>

================分割線================

5. swfobject

http://code.google.com/p/swfobject/

================分割線================

6. 單embed顯示 ie7和ff3下都能正常顯示

<embed allowscriptaccess="never" allownetworking="internal" invokeurls="false" src="http://chabudai.sakura.ne.jp/blogparts/honehoneclock/honehone_clock_tr.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" quality="high" autostart="0" wmode="transparent" width="100%" height="300" align="middle">


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM