[Greasemonkey] javascript scope between browsers

Aaron Boodman boogs at youngpup.net
Fri Oct 20 14:43:36 PDT 2006


So you want to open a window from a greasemonkey script, then from
that window call functions defined in the greasemonkey script.

Um... So greasemonkey runs in a separate scope from either window. So
you could basically do the reverse of unsafeWindow with something like
this:

unsafeWindow.gmScope = this;

|this| points to the global scope unless you happen to be running as a
method of an object at the time.

It's a really ugly solution though. What are you really trying to do?
Usually what you want to do is hook events in the content document,
then do work in Greasemonkey land, then change the content as a
result.

- a

On 10/20/06, James Cowan <cowanj at freenet.co.uk> wrote:
> I cannot get this to work. It is not a function within the window I want to
> call but within the firefox extension or gm script (basically extension
> based ipc).
>
> In some circumstances I can do a setTimeout call and it works.
>
> For example in the child window I can do
>
> window.opener.setTimeout("Somefunction()", 1) and it works
>
> In the parent window childWdw.setTimeout("Somefunction()", 1) does not work.
>
> James
>
> ----- Original Message -----
> From: "Aaron Boodman" <boogs at youngpup.net>
> To: <greasemonkey at mozdev.org>
> Sent: Thursday, October 19, 2006 6:37 PM
> Subject: Re: [Greasemonkey] javascript scope between browsers
>
>
> > On 10/19/06, Anthony Lieuallen <arantius at gmail.com> wrote:
> >> On 10/19/2006 9:07 AM, James Cowan wrote:
> >> > I am puzzled by javascript scope within greasemonkey...
> >> > Is there any way around this?
> >>
> >> (Not intentionally rude but...) Learn how greasemonkey works.  A good
> >> place to start:
> >> http://www.oreillynet.com/pub/a/network/2005/11/01/avoid-common-greasemonkey-pitfalls.html
> >
> > If you want to call functions in the child window, then you need either:
> >
> > wdw.unsafeWindow.someFunction();
> >
> > or:
> >
> > wdw.location.href = "javascript:someFunction()"
> >
> > The second is actually preferred, for security reasons.
> >
> > - a
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey at mozdev.org
> http://mozdev.org/mailman/listinfo/greasemonkey
>


More information about the Greasemonkey mailing list