我正在使用SWFObject来播放闪存SWF文件。SWF文件支持多个闪存变量。当我试图传递一个包含单引号和双引号混合的闪存变量的复杂值时,当SWFObject将完全呈现的内容写入为flash对象预留的DIV时,会发生一些不好的事情。
下面的代码显示了SWFObject将呈现的内容写入的名为DIV的闪存内容,以及与SWFObject交互的Javascript代码:
<!-- Div that will receive the Flash object. This DIV is written to by SWFObject.js. Therfore It's name must match the name
in the so.write() statement below. -->
<div id="flashcontent">
</div>
<!-- Div that will receive the Flash object. This DIV is written to by SWFObject.js. Therfore It's name must match the name
in the so.write() statement below. -->
<div id="flashcontent">
</div>
<!-- Create the tag cloud -->
<script type="text/javascript">
var so = new SWFObject("/Content/flash/tagcloud.swf", "tagcloud", "600", "400", "7", "#336699");
so.addParam("wmode", "transparent");
so.addVariable("mode", "tags");
so.addVariable("distr", "true");
so.addVariable("tcolor", "0xff0000");
so.addVariable("hicolor", "0x000000");
so.addVariable("tagcloud", "<tags><a href='javascript:showMessage(\"tag1\");' style='9'>tag one</a><a href='javascript:showMessage(\"tag2\");' style='12'>Tag two</a></tags>");
so.write("flashcontent");
</script>如您所见,我试图转义传递给Javascript showMessage()函数的字符串参数周围的双引号。但是,当呈现闪存内容DIV内容时,如下所示:
<div id="flashcontent"><embed type="application/x-shockwave-flash" src="/Content/flash/tagcloud.swf" width="600" height="400" id="tagcloud" name="tagcloud" bgcolor="#336699" quality="high" wmode="transparent" flashvars="mode=tags&distr=true&tcolor=0xff0000&hicolor=0x000000&tagcloud=<tags><a href='javascript:showMessage(" tag1");'="" style="9">tag one<a href='javascript:showMessage("tag2");' style="12">Tag two</a>"/></div>第一个转义双引号被解释为未转义的双引号,这会破坏格式,从而导致无效的超链接。如果我删除未转义的引号,内容如下:
<div id="flashcontent"><embed type="application/x-shockwave-flash" src="/Content/flash/tagcloud.swf" width="600" height="400" id="tagcloud" name="tagcloud" bgcolor="#336699" quality="high" wmode="transparent" flashvars="mode=tags&distr=true&tcolor=0xff0000&hicolor=0x000000&tagcloud=<tags><a href='javascript:showMessage(tag1);' style='9'>tag one</a><a href='javascript:showMessage(tag2);' style='12'>Tag two</a></tags>"></div>现在,格式是正确的,网页是健全的。当然,当我的ShowMessage()函数显示消息时,我会得到“未定义”,因为tag1和tag2不是有效的Javascript变量名。
SWFObject添加变量方法是否对转义双引号做了一些非常规操作?如何创建addvariable将接受的字符串,以便在Javascript方法参数周围获得双引号?
发布于 2013-08-19 15:40:23
您正在使用一个非常过时的swfobject版本。尝试最新版本(2.2)或2.3测试版,它们各自在引擎盖下处理不同的params。2.3在你的情况下可能最有效。
https://stackoverflow.com/questions/18306032
复制相似问题