【问题标题】:loading swf on chrome with jquery使用 jquery 在 chrome 上加载 swf
【发布时间】:2011-02-02 07:01:53
【问题描述】:
在 chrome 中,除非单击 div,否则 swf 不会加载,我做错了什么
var html += '<div align="center"><OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="myMovieName">';
html += ' <PARAM NAME="movie" VALUE="/media/cam.swf" /> <PARAM NAME="quality" VALUE="high" /> <PARAM NAME="bgcolor" VALUE="#FFFFFF" /> <EMBED href="/media/players/camera.swf" src="/media/players/camera.swf" quality=high bgcolor=#FFFFFF NAME="myMovieName" ALIGN="" TYPE="application/x-shockwave-flash"> </EMBED> </OBJECT></div>';
$("#contents").append(html);
【问题讨论】:
标签:
jquery
html
jquery-ui
google-chrome
flash
【解决方案1】:
使用 JavaScript 加载 swfs 的首选方法是使用 swfobject,而不仅仅是纯字符串和 jQuery。以字符串方式执行此操作时会出现太多问题。
一个例子:
<!-- Include swfobject -->
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js"></script>
<!-- Put this somewhere on your page -->
<div id="place_to_put_the_swf">
The content inside this div will be seen if
the user doesn't have flash installed.
Put an image, error message or whatever here.
</div>
<!-- This script with replace the div above with the following swf.
The parameters are filename, id of the div, width, height and flash version. -->
<script>
swfobject.embedSWF("file.swf", "place_to_put_the_swf", 400, 300, "7");
</script>
当然,如果您愿意,您可以使用 jQuery 渲染 div,然后运行 embedSWF 函数,这一切都在您的 JavaScript 中。