2013-08-19 67 views
0

我正在使用SWFObject播放Flash SWF文件。 SWF文件支持多個閃存變量。當我嘗試爲其中一個包含單引號和雙引號混合的Flash變量傳遞一個複雜值時,SWFObject將完全呈現的內容寫入爲閃存對象留出的DIV時會發生錯誤。在SWFObject中添加混合引號的問題addvariable調用

這裏是下面的代碼,顯示了DIV命名flashcontent是SWFObject的呈現內容寫入,以及JavaScript代碼與SWFObject的交互:

<!-- 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()函數。然而,當flashcontent 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&amp;distr=true&amp;tcolor=0xff0000&amp;hicolor=0x000000&amp;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&amp;distr=true&amp;tcolor=0xff0000&amp;hicolor=0x000000&amp;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()函數顯示消息時,我得到「undefined」,因爲tag1tag2是無效的Javascript變量名稱。

SWFObject 增加變量方法做任何非正統的逃脫雙引號?如何創建一個字符串,加變量將接受,以便我可以得到我的Javascript方法參數雙引號?

回答

1

你正在使用一個非常過時的swfobject版本。嘗試最新版本(2.2)或2.3測試版,它們各自在引擎蓋下處理不同的參數。 2.3在你的情況下可能效果最好。

+0

謝謝。我似乎無法找到SWFObject 2.3,只有2.2。你有鏈接嗎? –

+0

2.2完成了這項工作。你說SWFObject的舊副本有問題是正確的。如果您找到2.3的鏈接,請發帖。再次感謝。 –

+1

2.3測試版在GitHub上。 http://github.com/swfobject/swfobject – pipwerks