2

I'm building an Firefox Add-On That is suposed to read all in the HTML doc.

My problem is: I Can't make my JS in XUL read the HTML elements inside the HTML document.

I already tried

content.document.getElementsByTagName('a')

And

document.documentElement.getElementsByTagName('a')  

What am I doing Wrong?

Justin Johnson
  • 30,978
  • 7
  • 65
  • 89
  • I'm assuming you have JavaScript that you've included in a `browser.xul` that's overlaying the browser window, right? – Wayne Mar 23 '11 at 15:24
  • What lwburk said, and also, you should make sure your script runs after the browser window is loaded, rather than just running immediately. – Tyler Mar 23 '11 at 16:58
  • I'm running in a index.xul. My Js functions is only called when in the onclick event. This event is called by an Button that I put in the Statusbar. – Felipe Rodrigues Mar 23 '11 at 17:06
  • `content.document.getElementsByTagName('a')` should work, what result(s) are you getting? – Neil Mar 27 '11 at 21:06

3 Answers3

0

Have you tried window.content.getElementsByTagName('a') and window._content.getElementsByTagName('a') ?

MDC sais _content is deprecated and you should use the first one.

If it's not working, I would say the problem is somwhere else.

wildcard
  • 7,353
  • 3
  • 27
  • 25
  • I finally got it working. At first i Used .content, But then I installed jQuery at my XUL Extension and now it's even easier to access the DOM. – Felipe Rodrigues Mar 28 '11 at 11:34
0

Using jQuery is easy -

First add it to your overlay.xul

<script type="application/x-javascript" src="chrome://parentalcontrolbs/content/jquery-1.5.1.min.js" />

Than access DOM code using:

Ex:

    doc = content.document;
    $("a:contains(flamengo)", doc).html();
0

Maybe you should try this:

window.opener.content.document.getElementsByTagName("a")

This is working in my extension. Good luck!

Darxis
  • 1,482
  • 1
  • 17
  • 37