[Greasemonkey] reading document tree of iframe

Aaron Boodman zboogs at gmail.com
Tue Aug 8 12:33:50 EDT 2006


Yeah, Greasemonkey runs in the same reduced permission land that
regular webpages do, which means that it cannot reach across frames
from different domains.

You might be able to do what you want akwardly by writing two scripts
-- one for the iframe domain and one for parent document domain.

I can't think of an obvious way to get them to talk to each other
short of bouncing it off a server you control, but I have heard about
this cool hack where you have this structure:

[parent document - domain a
  [iframe - domain b
    [iframe - domain a

In this scenario, I heard that the parent document could reach the
nested iframe because they are the same domain with a path like:
window.frames[0].frames[0]. If that's true, then the iframe script
could create a nested iframe in the right domain, and you could use
that to communicate between the two scripts.

Yes, this is horrific. Sorry, maybe this is a better project for a
fully-fledged extension.

- a

On 8/8/06, James Cowan <cowanj at freenet.co.uk> wrote:
> Hi
>
> I am loading a document into an iframe and then want to analyse the dom tree
> of the loaded document.
>
> Using iframe.addEventListener('load', getDomTree, true); I can attach some
> code to analyse the tree fine when it is from the same domain as the
> document that contains the iframe. When I load a url into the iframe from a
> different domain, I do not seem to be able to read it
> (iframe.contentWindow.document is null).
>
> I guess this is probably a general firefox permissions problem rather than a
> specific greasemonkey query but I was wondering whether anyone knew how to
> get around this problem.
>
> James
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list