0

我是Firefox的擴展開發新手,一般在移動版本中,而且我面臨的這個問題讓我瘋狂。getElementsByName在firefox mobile的restartless(bootstrapped)擴展中

我需要提取具有特定標記名稱的元素,例如或<p><script>。當然,我想過使用getElementsByTagName(),但它不適合我。此外,我不知道我應該把它放在哪裏,因爲當我將它鏈接到門鎖按鈕中的某個功能時,它不起作用。如果我更改爲啓動函數,它將顯示警報窗口,但是會顯示一個空結果(空值)。

我真的陷入困境,我需要你的幫助。這裏,代碼行我使用爲:

doc=getBrowser().selectedTab.linkedBrowser.contentDocument; 
frames=doc.getElementsByTagName("script"); 

我只顯示所提取的元件的陣列的長度在一個警告窗口,並在烤麪包,當我在doorhanger按下一個按鈕:

label: "JavaScript",// the button label in the doorhanger 
callback: function() { 
    Services.prompt.alert(null,"the iframes ","Frames Tag shown "+frames.length);// the alert window 
    aWindow.NativeWindow.toast.show("Frames Tag shown "+frames.length, "long");//the toast 
} 
+0

請添加你如何使用'frames'片段。 – Teemu 2013-02-23 12:41:48

+0

我只是在警報窗口中顯示提取元素數組的長度,當我按下門鎖中的按鈕時: – user2102196 2013-02-23 13:02:53

回答

0

以及感謝所有您的幫助,我找到了解決辦法:該代碼綁定到顯示doorhanger菜單按鈕:

init();// initialization of the vriables otherwise it won't work 
    var tab = window.BrowserApp.selectedTab; 
    doc = tab.window.document;// getting the DOM 
    iframes=doc.getElementsByTagName("iframe");// the the iframes 
0

桌面和移動擴展之間有很多不同。首先,後者不提供全局getBrowser()或gBrowser。相反,你必須使用BrowserApp object

+0

我已經嘗試過,tab = BrowserApp.selectedTab,但我不知道如何訪問要獲取元素的Tab的DOM。 – user2102196 2013-02-23 14:48:46

+0

BrowserApp頁面有一個指向Tab對象頁面的鏈接。 – paa 2013-02-23 15:52:25

+0

我試過了,但還是不行。他們是否有任何想法或建議:var ios = Components .classes [「@ mozilla.org/network/io-service;1」] .getService(Components.interfaces.nsIIOService); doc = BrowserApp.selectedTab.window.document; frames = doc.getElementsByTagName(「script」); – user2102196 2013-02-23 18:30:39