萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 網頁製作 >> HTML5 教學

SWFObject 嵌入 Flash 動畫的 HTML 標準寫法(歷史參考,現代項目請避免 Flash)

歷史背景

SWFObject 是一個 JavaScript 庫,用於**標準化、無障礙、跨瀏覽器**嵌入 Flash (.swf) 内容,解決 ``/`` 標籤混亂、ActiveX 激活提示等問題。**Flash 已於 2020 年底停止支援**,現代項目請改用 HTML5 Canvas/WebGL/WebAssembly/WebCodecs 等技術。本文僅供維護舊專案參考。

標準嵌入代碼結構

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <title>SWFObject embed</title>
  <script src="swfobject.js"></script>
  <script>
    swfobject.embedSWF(
      "myContent.swf",   // swf 路徑
      "myContent",       // 容器元素 id
      "300", "120",      // 寬、高
      "9.0.0",           // 最低 Flash Player 版本
      "expressInstall.swf" // 可選:快速安裝引導 swf
      // 可選參數:flashvars, params, attributes, callbackFn
    );
  </script>
</head>
<body>
  <div id="myContent">
    <p>suoling.net TEST</p> <!-- 替換內容:無 Flash 時顯示 -->
  </div>
</body>
</html>

核心參數詳解

參數類型說明
swfUrlString.swf 文件路徑(相對/絕對)
idString容器 DOM 元素 id(會被替換為 object/embed)
width / heightString/Number寬高,支援百分比
versionString最低 Flash Player 版本(如 "10.0.0")
expressInstallSwfString可選,Express Install 引導檔
flashvarsObject傳給 Flash 的變量 `{key:val}`
paramsObjectobject/embed 參數:`wmode`、`allowScriptAccess`、`allowFullScreen`、`quality`、`bgcolor` 等
attributesObject賦予 object 標籤的屬性:`id`、`name`、`class`、`style`、`align`
callbackFnFunction嵌入完成回調 `function(e){ e.success, e.id, e.ref }`

常用 params 設置

var params = {
  wmode: "transparent",        // 透明模式,允許 HTML 疊加
  allowScriptAccess: "always", // 允許 JS<->AS 互調
  allowFullScreen: "true",     // 允許全屏
  quality: "high",             // 渲染質量
  bgcolor: "#ffffff"           // 背景色
};

優雅降級與無障礙

  • 容器 `
    ` 內放置**替換內容**(文字、圖片、下載鏈接),無 Flash 環境自動顯示。
  • 支援 ``、`<nojs>` 進一步降級(極少見)。</li> <li>生成的 `<object>` 標籤符合 HTML 標準,無專有屬性污染。</li> </ul> <h2>現代替代技術棧</h2> <table border="1" cellpadding="6" cellspacing="0"> <thead><tr><th>舊技術</th><th>現代替代</th><th>適用場景</th></tr></thead> <tbody> <tr><td>Flash 動畫</td><td>Lottie (Bodymovin) / CSS Animation / Web Animations API</td><td>矢量動畫、UI 微動效</td></tr> <tr><td>Flash 遊戲</td><td>HTML5 Canvas + JS / WebAssembly (Unity/Godot 導出) / WebGPU</td><td>高性能 2D/3D 遊戲</td></tr> <tr><td>Flash 視頻播放器</td><td><video> + HLS/DASH / MSE / WebCodecs</td><td>流媒體播放</td></tr> <tr><td>Flash 豐富文本編輯器</td><td>contenteditable + ExecCommand / Input Events API / ProseMirror / Slate / TipTap</td><td>富文本編輯</td></tr> <tr><td>Flash 圖表/儀表板</td><td>ECharts / Chart.js / D3 / Highcharts / ApexCharts (Canvas/SVG)</td><td>數據可視化</td></tr> </tbody> </table> <h2>結語</h2> <p>SWFObject 曾是嵌入 Flash 的黃金標準,但 Flash 時代已終結。維護舊系統時請謹慎使用隔離沙箱;新項目請毫不猶豫擁抱開放、安全、高性能的 Web 標準技術棧。</p> <div class="ad2"> <script language='javascript' src='/ad/tad.js'></script> </div> </div> <div> <div class="pageNum"> <ul> <li>上一篇程序編程: <a class='LinkPrevArticle' href='https://twcomputer.wsxdn.com/programming/webproduction/html5/201511/162778.html' >jQuery&nbsp;過濾&nbsp;HTML&nbsp;標籤屬性特殊字符:防&nbsp;XSS&nbsp;的實體編碼替換對照表</a> <li>下一篇程序編程: <a class='LinkNextArticle' href='https://twcomputer.wsxdn.com/programming/webproduction/html5/201511/162780.html' >PHP&nbsp;過濾&nbsp;HTML&nbsp;標籤完全指南:strip_tags()&nbsp;與&nbsp;htmlspecialchars()&nbsp;差異與應用場景</a> </ul> </div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> <div class=hebxbne_left-div-2> <h2 style="text-align:left">HTML5 教學排行</h2> <ul> <li><a class="font7 nleft" title="CSS&nbsp;絕對定位&nbsp;核心原理、脫離文檔流與實戰陷阱全解析" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201708/181012.html">CSS&nbsp;絕對定位&nbsp;核心原理、脫離文檔流與實戰陷阱全解析</a></li> <li><a class="font7 nleft" title="超文本標記語言(HTML)核心概念與入門指南" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201511/162804.html">超文本標記語言(HTML)核心概念與入門指南</a></li> <li><a class="font7 nleft" title="解決&nbsp;HTML&nbsp;內聯元素換行產生多餘空白節點的完整方案" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157909.html">解決&nbsp;HTML&nbsp;內聯元素換行產生多餘空白節點的完整方案</a></li> <li><a class="font7 nleft" title="HTML5&nbsp;開發者必備:特性檢測、Polyfill、框架與調試工具全景圖" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35566.html">HTML5&nbsp;開發者必備:特性檢測、Polyfill、框架與調試工具全景圖</a></li> <li><a class="font7 nleft" title="JavaScript&nbsp;過濾&nbsp;HTML&nbsp;標籤:正則與&nbsp;DOM&nbsp;方案效能比較" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/165328.html">JavaScript&nbsp;過濾&nbsp;HTML&nbsp;標籤:正則與&nbsp;DOM&nbsp;方案效能比較</a></li> </ul> </div> <div class=kenbxne_js></div> </div> <div class="nright hebxbne_right"> <div class=guanggao1 id=guanggao_r1></div> <div class=kenbxne_js></div> <div class=hebxbne_right-div1> <h2>推薦文章</h2> <div class=kenbxne_js></div> <ul class=hebxbne_right-list1> <li><a class="font7 nleft" title="HTML&nbsp;a&nbsp;標籤&nbsp;href&nbsp;屬性完整指南:URL&nbsp;類型、相對絕對路徑、片段識別…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201602/171465.html">HTML&nbsp;a&nbsp;標籤&nbsp;href&nbsp;屬性完整指南:URL&nbsp;類型、相對絕對路徑、片段識別…</a></li> <li><a class="font7 nleft" title="HTML5來襲:設計師如何駕馭新世代網頁技術?" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35573.html">HTML5來襲:設計師如何駕馭新世代網頁技術?</a></li> <li><a class="font7 nleft" title="HTML&nbsp;&lt;input&gt;&nbsp;標籤完整屬性指南:類型、驗證、無障礙與最佳實務" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/166314.html">HTML&nbsp;&lt;input&gt;&nbsp;標籤完整屬性指南:類型、驗證、無障礙與最佳實務</a></li> <li><a class="font7 nleft" title="HTML&nbsp;標籤類型完整分類:單雙標籤、屬性語法、字元參考、註解與文件結構規範" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/166312.html">HTML&nbsp;標籤類型完整分類:單雙標籤、屬性語法、字元參考、註解與文件結構規範</a></li> <li><a class="font7 nleft" title="HTML&nbsp;在線編輯器核心原理深度解析:designMode、contentEdi…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157455.html">HTML&nbsp;在線編輯器核心原理深度解析:designMode、contentEdi…</a></li> <li><a class="font7 nleft" title="國際大牌頂尖&nbsp;H5&nbsp;案例賞析:寶馬&nbsp;MINI、標致、阿迪達斯、寶潔&nbsp;Old&nbsp;Sp…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/35227.html">國際大牌頂尖&nbsp;H5&nbsp;案例賞析:寶馬&nbsp;MINI、標致、阿迪達斯、寶潔&nbsp;Old&nbsp;Sp…</a></li> <li><a class="font7 nleft" title="HTML5&nbsp;Geolocation&nbsp;API&nbsp;取得地理位置完整實作:高精度定位、百…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157749.html">HTML5&nbsp;Geolocation&nbsp;API&nbsp;取得地理位置完整實作:高精度定位、百…</a></li> <li><a class="font7 nleft" title="HTML&nbsp;表格屬性完整參考:border、cellspacing、cellpad…" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/167295.html">HTML&nbsp;表格屬性完整參考:border、cellspacing、cellpad…</a></li> <li><a class="font7 nleft" title="HTML&nbsp;網頁製作實用技巧&nbsp;8&nbsp;則(精簡版)" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201510/157802.html">HTML&nbsp;網頁製作實用技巧&nbsp;8&nbsp;則(精簡版)</a></li> <li><a class="font7 nleft" title="HTML&nbsp;標籤學習路徑:結構、CSS&nbsp;整合與專案實戰架構" href="https://twcomputer.wsxdn.com/programming/webproduction/html5/201512/165330.html">HTML&nbsp;標籤學習路徑:結構、CSS&nbsp;整合與專案實戰架構</a></li> </ul> </div> </div> <div class=kenbxne_js></div> </div> <div class=kenbxne_js></div> <div class=plnebxmj> <div class="plnebxmj-2 flink"> <h2><a class=bottom href="https://twcomputer.wsxdn.com/" target=_blank>萬盛學電腦網</a>| <a class=bottom hreflang="ja" href="https://jp.wsxdn.com/" target=_blank>日本語版</a> | <a class=bottom onclick="this.style.behavior='url(#default#homepage)';this.sethomepage('https://twcomputer.wsxdn.com');" href="#">設為首頁</a> | <a class=bottom href="javascript:window.external.addfavorite('https://twcomputer.wsxdn.com','萬盛學電腦網');">加入收藏</a></h2> </div> <div class=knemnnx></div> </div> <div class="ojwbxnks">copyright © <a title="萬盛學電腦網" href="https://twcomputer.wsxdn.com/" target=_blank>萬盛學電腦網</a> all rights reserved <br> </div> </div> </body> </html>