On Tue, Aug 25, 2009 at 8:33 AM, mack<[email protected]> wrote:
>
> Hi,
>
> I have problems going through the HTML DOM node tree from a user
> script (or context script):
>
> var d = document.createElement('div');
>
> var varRoot = document.childNodes[0];
> var varBody = varRoot.childNodes[1];
> var name = varBody;
>
> d.innerHTML = name;
> document.body.appendChild(d);
FWIW, this script has some bugs. At line 4 "name" contains a reference
to a node. Then you are trying to assign that node to "innerHTML"
which wants a string.
> which returns "undefined"
If that is happening, it sounds like your assumptions about the
structure of the document are not correct. Perhaps the root does not
have two child nodes in this case. It is usually better to use higher
level DOM APIs because they are less brittle. In this case, you could
use document.getElementsByTagName("body")[0].
> I understand from Aaron's previous posting that this might be caused
> by the fact that the default content scripts run in DOMContentLoaded
> event.
No, at DOMContentLoaded, the entire DOM should be present.
> What can I do to access the whole DOM object hierarchy of the page? I
> already use @run-at document-end.
It should work. If you can't figure out, please post again and include
the HTML for the page you are trying to manipulate.
- a
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en
-~----------~----~----~----~------~----~------~--~---