MozillaZine

using getElementsByTagName in extension

Talk about add-ons and extension development.
tuxfood
 
Posts: 1
Joined: June 12th, 2007, 10:54 am

Post Posted June 12th, 2007, 11:01 am

hi

I am developing an extension where i have to access the DOM loaded in an iframe element.
One method i found out was to access the frame element's contentDocument property

So to access the iframe element, i have to use the document.getElementByTagName function.
Another method would be use document.getElementById function, but i donot ( and will not ) know the id of the iframe element.

i tried the following simple code and its failing

Code: Select all

   var oWindow = GetFocusedWindow(); // to return the window in which we show the iframe loaded page

   var oIframe = oWindow.document.getElementsByTagName( "iframe" );

   alert( oIframe.length ) ;



this length value is shown as 0 .

Am i supposed to use some other method like XPCNativeWrapper ?

please help me with is.. This the only blocking part in this development part! :(

thanks in advance

haynes

Zoolcar9

User avatar
 
Posts: 2225
Joined: November 9th, 2004, 6:45 pm
Location: Jakarta, Indonesia (UTC+7)

Post Posted June 12th, 2007, 11:16 pm

Code: Select all
var oIframe = content.document.getElementsByTagName("iframe");

See:
- Getting document of currently selected tab
- Working with windows in chrome code

To get the document object in a frame:
Code: Select all
var docObject = oIframe[index].contentDocument

My Firefox information | Add-ons | GitHub

"With great power, comes great desire to show it off."

max1million
 
Posts: 2810
Joined: November 15th, 2004, 5:03 am

Post Posted June 13th, 2007, 12:23 am

I don't know where GetFocusedWindow() comes from but for me (using Javascript Command extension) it is "undefined", and 'may', be your problem. Some other questions are:

Is it an iframe in a content document (webpage)?
window.content.document.getElementsByTagName("iframe").length;

Or in a chrome window document?
window.document.getElementsByTagName("iframe").length

Or could it be a "browser" instead of an "iframe"?
window.content.document.getElementsByTagName("browser").length;// content document
window.document.getElementsByTagName("browser").length;// chrome document

Or maybe either type of frame?
window.content.frames.length; // content window (or frame)
window.frames.length; // chrome window (or frame)

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 2 guests