Search code examples
javascriptandroidfirefox-addongetelementsbytagnamefirefox-addon-restartless

getElementsByName in restartless (bootstrapped) extension for firefox mobile


I'm new in extensions development with Firefox in general, and in the mobile version in specific, and I'm facing this problem that's making me insane.

I need to extract elements with a certain tag name, example <iframe> or <p> or <script>. Naturally I thought about using getElementsByTagName(), but it doesn't work for me. Besides, I don't know where exactly I should put it, since when I link it to a function in a button in a doorhanger, it doesn't work. If I change to the startup function it displays the alert window, but with an empty result (null).

I'm really stuck and i need your help guys. Here the code lines I'm using for that:

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

I'm just displaying the length of the array of the extracted elements in an alert window and in a toast, when I press a button in a 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
}

Solution

  • well thanks all for your help, I found the solution: this code is binded to the menu button showing the 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