2010-08-18 66 views
4

我想創建一個使用flex應用程序的Firefox擴展。我試圖用XUL類型(< iframe>和< browser>)來包裝它,而且我沒有偏好使用哪一個...無論哪一個都適用。如何爲瀏覽器或iframe元素動態設置「src」(Firefox擴展)

問題是,無論何時使用相對路徑(通過chrome://或mySWF.html訪問),flash都無法加載。

我有一個方法來搜索絕對路徑(它張貼在下面),但我不能爲我的生活找出一種方法來動態更改iframe或瀏覽器的src。

<script type="text/javascript"> 
function loadSWF() { 
    alert("loadSWF!"); 
    var fullPath = "file:///" + extensionPath.path.replace(/\\/g,"/") + "/chrome/content/HelloWorld.html"; 
    top.document.getElementById('AppFrame').setAttribute("src",fullPath); 
} 
</script> 

下面是我2種調用Flex應用程序的方法:

<iframe 
    type="content" 
    src=?????? 
    flex="1" 
    id="AppFrame" 
    name="AppFrame" 
    onLoad="loadSWF();"/> 

<browser 
    id="browserid" 
    type="content" 
    src=?????? 
    flex="1"/> 

我怎麼能說我的函數來設置src屬性???

+0

聽起來像是你可能沒有正確設定Chrome清單。 https://developer.mozilla.org/en/chrome_manifest – MatrixFrog 2010-08-19 04:11:05

回答

1

1)動態設置src工作正常(見下面的測試用例)。

2)To get a URL of a file, use nsIIOService.newFileURI()而不是試圖手動轉換。

3)onLoad="loadSWF();"在您的iframe中存在可疑情況,您應該發佈完整的XUL代碼,以顯示它們如何融合在一起。您應該不是從iframe的裝入處理程序調用loadSWF,而是從XUL文檔的裝入處理程序或另一個事件中調用loadSWF。

測試用例#1:

<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
<window id="yourwindow" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" xmlns:html="http://www.w3.org/1999/xhtml"> 
<script type="text/javascript"> 
<![CDATA[ 
function f() { 
document.getElementById("z").setAttribute("src", "http://google.com/") 
} 
]]> 
</script> 
<iframe type="content" id="z"/> 
<button onclick="f()"/> 
</window> 
相關問題