[英]getElementsByName in restartless (bootstrapped) extension for firefox mobile
我是使用Firefox進行擴展開發的新手,尤其是使用移動版本的擴展中的新手,我正面臨着使我發瘋的問題。
我需要提取具有特定標記名稱的元素,例如<iframe>
或<p>
或<script>
。 自然,我考慮過使用getElementsByTagName()
,但是它對我不起作用。 此外,我不知道該將其確切放置在什么地方,因為當我將其鏈接到門衣架中按鈕上的功能時,它不起作用。 如果更改為啟動功能,它將顯示警報窗口,但結果為空(空)。
我真的被困住了,我需要你的幫助。 這是我正在使用的代碼行:
doc=getBrowser().selectedTab.linkedBrowser.contentDocument;
frames=doc.getElementsByTagName("script");
當我按下門衣架中的按鈕時,我只是在警報窗口和烤面包中顯示提取的元素數組的長度:
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
}
桌面擴展和移動擴展之間有很多區別。 首先,后者不提供全局getBrowser()或gBrowser。 相反,您必須使用BrowserApp對象 。
很好,感謝大家的幫助,我找到了解決方案:這段代碼綁定到顯示門掛的菜單按鈕:
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.