JavaScript 不工作 SWFObject 未定义

发布于 2024-12-13 22:47:24 字数 651 浏览 0 评论 0原文

我收到此错误“Microsoft JScript 运行时错误:'SWFObject' 未定义”

我的代码如下所示

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>   
    <div id="flashcontent">This text is replaced by the Flash movie. </div>   
<script type="text/javascript">
    var rndPick = 2;
    var rndPick = Math.floor(Math.random() * 16) + 1;
    var movie = "/Flash/sam" + rndPick + ".swf";
    var so = new SWFObject(movie, "mymovie", "955", "170", "8", "#336699");
    so.write("flashcontent");
    setTimeout("location.reload(true);", 14500);  
</script>  

I am getting this error "Microsoft JScript runtime error: 'SWFObject' is undefined"

my code looks like this

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>   
    <div id="flashcontent">This text is replaced by the Flash movie. </div>   
<script type="text/javascript">
    var rndPick = 2;
    var rndPick = Math.floor(Math.random() * 16) + 1;
    var movie = "/Flash/sam" + rndPick + ".swf";
    var so = new SWFObject(movie, "mymovie", "955", "170", "8", "#336699");
    so.write("flashcontent");
    setTimeout("location.reload(true);", 14500);  
</script>  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

够运 2024-12-20 22:47:24

您使用的是 SWFObject 1.5 语法,但链接到 SWFObject 2.2 JS 文件。 SWFObject 1.5 和 2.2 不兼容。

重写您的 SWFObject 代码以使用 2.2 语法。以下是转换为 SWFObject 2.2 语法的代码。请注意,当 DOM 完成加载时,swfobject.embedSWF 会自动执行。

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>   

<script type="text/javascript">
var rndPick = Math.floor(Math.random() * 16) + 1;
var movie = "/Flash/sam" + rndPick + ".swf";

var flashvars = {}; //empty for this example
var params = { bgcolor: "#336699" };  //sets background color
var attributes = { id: "mymovie" }; //sets ID of <object> to "mymovie"

//Optional callback function gets executed after <object> is created
var callbackFn = function (){
    setTimeout("location.reload(true);", 14500);
};

swfobject.embedSWF(movie, "flashcontent", "955", "170", "8", false, flashvars, params, attributes, callbackFn);

</script> 
</head>

<body>
    <div id="flashcontent">This text is replaced by the Flash movie. </div>   
</body>

You're using SWFObject 1.5 syntax, but linking to the SWFObject 2.2 JS file. SWFObject 1.5 and 2.2 are incompatible.

Rewrite your SWFObject code to use the 2.2 syntax. Here is your code converted to SWFObject 2.2 syntax. Note that swfobject.embedSWF is automatically executed when the DOM has finished loading.

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>   

<script type="text/javascript">
var rndPick = Math.floor(Math.random() * 16) + 1;
var movie = "/Flash/sam" + rndPick + ".swf";

var flashvars = {}; //empty for this example
var params = { bgcolor: "#336699" };  //sets background color
var attributes = { id: "mymovie" }; //sets ID of <object> to "mymovie"

//Optional callback function gets executed after <object> is created
var callbackFn = function (){
    setTimeout("location.reload(true);", 14500);
};

swfobject.embedSWF(movie, "flashcontent", "955", "170", "8", false, flashvars, params, attributes, callbackFn);

</script> 
</head>

<body>
    <div id="flashcontent">This text is replaced by the Flash movie. </div>   
</body>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文