swfobject.embedSWF不工作?

时间:2016-11-30 05:27:44

标签: javascript html5 swfobject

以下使用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中的HTML & CSS: design and build websites

2 个答案:

答案 0 :(得分:11)

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

从Chrome 55开始的新“默认HTML”Flash策略不会初始化SWFObject用于检测Flash是否已安装的变量。具体而言,navigator.mimeTypes不再包含application/x-shockwave-flash,除非用户启用了Flash。其他浏览器也存在与click-to-run activation scheme中引入的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 param;其他参数在这里显示为可能的例子。

答案 1 :(得分:4)

自版本55以来,Chrome不会初始化swfobject安装Flash时需要检测的变量。 您可以将原始补丁应用于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);
        }