swfobject.embedSWF 不工作?

swfobject.embedSWF not working?

以下使用 SWFObject 将 Flash 动画嵌入 HTML 文档的代码仅显示备选内容。为什么?

<!DOCTYPE html>
<html>
    <head>
        <title>Adding a Flash Movie</title>
        <script type="text/javascript"
                src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js">
        </script>
        <script type="text/javascript">
            swfobject.embedSWF("flash/bird.swf", "bird", "400", "300", "8.0.0");
        </script>
    </head>
    <body>
        <div id="bird">
            <p>An animation of a bird taking a shower</p>
        </div>
    </body>
</html>

Chrome, IE 和 Firefox 都只显示 An animation of a bird taking a shower.

密码是a sample from the book HTML & CSS: design and build websites.

SWFObject 2.2 不再正常工作。 bug in SWFObject 已在 GitHub 上报告,但库未维护。

从 Chrome 55 开始的新“HTML 默认”Flash 策略不会初始化 SWFObject 用来检测是否安装了 Flash 的变量。具体来说,navigator.mimeTypes 不再包含 application/x-shockwave-flash,除非用户启用了 Flash。其他浏览器也有与 click-to-run activation scheme introduced as part of Flash’es end of life.

相关的类似问题

此时,最好的做法可能是简单地使用 <object> 嵌入 Flash。例如:

<object type="application/x-shockwave-flash" data="app.swf">
    <param name='movie' value="app.swf"/>
    <param name='bgcolor' value="#999999"/>
    <param name='FlashVars' value="var1=Hello&var2=Goodbye" />
    <param name='allowscriptaccess' value="sameDomain"/>
</object>

注意 (1) .swf 在两个地方指定 (2) 只有 movie 参数是必需的;此处显示了其他参数作为可能的示例。

Chrome's since version 55 does not initialize the variables that swfobject needs to detect if flash is installed. 您可以将原始补丁应用于 swfobject js 以跳过 hasPlayerVersion 检查:

-       if (hasPlayerVersion(swfVersionStr)) { // create SWF
+       try {  // create SWF
            var obj = createSWF(att, par, replaceElemIdStr);
            if (att.id == replaceElemIdStr) {
                setVisibility(replaceElemIdStr, true);
            }
            callbackObj.success = true;
            callbackObj.ref = obj;
-       }
-       else if (xiSwfUrlStr && canExpressInstall()) { // show Adobe Express Install
-           att.data = xiSwfUrlStr;
-           showExpressInstall(att, par, replaceElemIdStr, callbackFn);
-           return;
-       }
-       else { // show alternative content
+       } catch (e) {  // show alternative content
            setVisibility(replaceElemIdStr, true);
        }