|
List Info
Thread: Reference function
|
|
| Reference function |

|
2006-08-05 12:57:23 |
Hello.
I cannot get the page access the userscript functions.
[crop]
window.hello = function () { alert ('yay'); }
document.body.innerHTML += '<input
type="button"
onclick="window.hello()"
value="Try">';
document.body.innerHTML += '<input
type="button" onclick="hello()"
value="Try again">';
[/crop]
when I press the "Try" and the "Try
again" buttons, I get error messages...
What am I doing wrong?
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-05 15:22:39 |
On 8/5/2006 8:57 AM, Tracid wrote:
> I cannot get the page access the userscript functions.
> ...
> when I press the "Try" and the "Try
again" buttons, I get error messages...
> What am I doing wrong?
For security purposes, the "window" scope that
greasemonkey scripts run
in is not the window that the page runs in, it is a separate
but related
context that the page cannot access, on purpose.
The page context is the "unsafeWindow" object,
but it is not called
unsafe by accident. For an idea of how to get clicking on a
link to
reference it see my earlier message:
http://www.mozdev.org/pipermail/greasemonkey
/2006-August/009049.html
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-05 15:29:43 |
same question answered 1 day ago.
http://mozdev.org/pipermail/greasemonkey/2006-Au
gust/009048.html
Quoting Tracid <tracid zappmobile.ro>:
>
> I cannot get the page access the userscript functions.
> [crop]
> window.hello = function () { alert ('yay'); }
> document.body.innerHTML += '<input
type="button"
> onclick="window.hello()"
value="Try">';
> document.body.innerHTML += '<input
type="button" onclick="hello()"
> value="Try again">';
> [/crop]
>
> when I press the "Try" and the "Try
again" buttons, I get error messages...
> What am I doing wrong?
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey mozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-05 23:42:31 |
When you hit "new user script" for the first
time, we should open a
tab with this question and answer in it.
- a
On 8/5/06, Rod McGuire <mcguire telerama.com> wrote:
>
>
> same question answered 1 day ago.
> http://mozdev.org/pipermail/greasemonkey/2006-Au
gust/009048.html
>
> Quoting Tracid <tracid zappmobile.ro>:
> >
> > I cannot get the page access the userscript
functions.
> > [crop]
> > window.hello = function () { alert ('yay'); }
> > document.body.innerHTML += '<input
type="button"
> > onclick="window.hello()"
value="Try">';
> > document.body.innerHTML += '<input
type="button" onclick="hello()"
> > value="Try again">';
> > [/crop]
> >
> > when I press the "Try" and the
"Try again" buttons, I get error messages...
> > What am I doing wrong?
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey mozdev.org
> > http:
//mozdev.org/mailman/listinfo/greasemonkey
> >
>
>
>
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey mozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-06 01:45:04 |
Quoting Aaron Boodman <zboogs gmail.com>:
> When you hit "new user script" for the
first time, we should open a
> tab with this question and answer in it.
>
> - a
Maybe make things so you can only post to this list if you
are subscribed, and
to subscribe you have to check a box asserting that you have
read "Avoid Common
Pitfalls in Greasemonkey"
http://www.oreil
lynet.com/lpt/a/6257
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-06 01:58:52 |
On 8/5/06, Rod McGuire <mcguire telerama.com> wrote:
> Maybe make things so you can only post to this list if
you are subscribed, and
> to subscribe you have to check a box asserting that you
have read "Avoid Common
> Pitfalls in Greasemonkey"
>
> http://www.oreil
lynet.com/lpt/a/6257
Hmm, that seems a bit too hostile rather than helpful.
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-06 20:21:13 |
Well, I know it could be done with window.addEventListener
for load. I
admit that I read about unsafeWindow right after sending th
emessage.
But I've got the following code:
var c = seconds;
unsafeWindow.timedCount = function () {
var timer = document.getElementById
('counter').firstChild;
c=c-1;
var t = setTimeout ('timedCount ()',
1000);
timer.data = c+' seconds left';
if (c == 0) {
timer.data = 'Free';
clearTimeout (t);
document.location.reload ();
}
}
unsafeWindow.timedCount ();
Can I do something to get it work without unsafeWindow?
Cause I can't
get it work with addEventListener due to the function
looping...
Aaron Boodman wrote:
> When you hit "new user script" for the
first time, we should open a
> tab with this question and answer in it.
>
> - a
>
> On 8/5/06, Rod McGuire <mcguire telerama.com> wrote:
>>
>>
>> same question answered 1 day ago.
>> http://mozdev.org/pipermail/greasemonkey/2006-Au
gust/009048.html
>>
>> Quoting Tracid <tracid zappmobile.ro>:
>> >
>> > I cannot get the page access the userscript
functions.
>> > [crop]
>> > window.hello = function () { alert ('yay');
}
>> > document.body.innerHTML += '<input
type="button"
>> > onclick="window.hello()"
value="Try">';
>> > document.body.innerHTML += '<input
type="button" onclick="hello()"
>> > value="Try again">';
>> > [/crop]
>> >
>> > when I press the "Try" and the
"Try again" buttons, I get error
>> messages...
>> > What am I doing wrong?
>> >
_______________________________________________
>> > Greasemonkey mailing list
>> > Greasemonkey mozdev.org
>> > http:
//mozdev.org/mailman/listinfo/greasemonkey
>> >
>>
>>
>>
>>
>> _______________________________________________
>> Greasemonkey mailing list
>> Greasemonkey mozdev.org
>> http:
//mozdev.org/mailman/listinfo/greasemonkey
>>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey mozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-06 23:34:40 |
did you try reading, as suggested,
http://www.oreil
lynet.com/lpt/a/6257
or at least search it for the string
"setTimeout"?
Quoting Tracid <tracid zappmobile.ro>:
> Well, I know it could be done with
window.addEventListener for load. I
> admit that I read about unsafeWindow right after
sending th emessage.
> But I've got the following code:
>
> var c = seconds;
> unsafeWindow.timedCount = function () {
> var timer = document.getElementById
('counter').firstChild;
> c=c-1;
> var t = setTimeout ('timedCount ()',
1000);
> timer.data = c+' seconds left';
> if (c == 0) {
> timer.data = 'Free';
> clearTimeout (t);
> document.location.reload ();
> }
> }
> unsafeWindow.timedCount ();
>
> Can I do something to get it work without unsafeWindow?
Cause I can't
> get it work with addEventListener due to the function
looping...
>
> Aaron Boodman wrote:
> > When you hit "new user script" for the
first time, we should open a
> > tab with this question and answer in it.
> >
> > - a
> >
> > On 8/5/06, Rod McGuire <mcguire telerama.com> wrote:
> >>
> >>
> >> same question answered 1 day ago.
> >> http://mozdev.org/pipermail/greasemonkey/2006-Au
gust/009048.html
> >>
> >> Quoting Tracid <tracid zappmobile.ro>:
> >> >
> >> > I cannot get the page access the
userscript functions.
> >> > [crop]
> >> > window.hello = function () { alert
('yay'); }
> >> > document.body.innerHTML += '<input
type="button"
> >> > onclick="window.hello()"
value="Try">';
> >> > document.body.innerHTML += '<input
type="button" onclick="hello()"
> >> > value="Try again">';
> >> > [/crop]
> >> >
> >> > when I press the "Try" and
the "Try again" buttons, I get error
> >> messages...
> >> > What am I doing wrong?
> >> >
_______________________________________________
> >> > Greasemonkey mailing list
> >> > Greasemonkey mozdev.org
> >> > http:
//mozdev.org/mailman/listinfo/greasemonkey
> >> >
> >>
> >>
> >>
> >>
> >>
_______________________________________________
> >> Greasemonkey mailing list
> >> Greasemonkey mozdev.org
> >> http:
//mozdev.org/mailman/listinfo/greasemonkey
> >>
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey mozdev.org
> > http:
//mozdev.org/mailman/listinfo/greasemonkey
> >
>
> _______________________________________________
> Greasemonkey mailing list
> Greasemonkey mozdev.org
> http:
//mozdev.org/mailman/listinfo/greasemonkey
>
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
| Reference function |

|
2006-08-08 11:40:46 |
> unsafeWindow.timedCount = function () {
> ...
> var t = setTimeout ('timedCount ()', 1000);
> ...
> }
> unsafeWindow.timedCount();
>
> Can I do something to get it work without unsafeWindow?
Cause I can't
> get it work with addEventListener due to the function
looping...
Learn how to use function references instead of named
functions.
In this case you should probably just keep the function to
yourself in
the GM scope:
function timedCount()
{
...
setTimeout( timedCount, 1000 );
...
}
timedCount();
Registering it to invoke via addEventListener isn't any
harder than
the setTimeout:
document.addEventListener( 'load', timedCount, false );
and in case you absolutely want to list the callback as an
inline
function literal in that call (some do; personally I find it
less
readable for anything but oneliners), the function has a
reference to
itself known as arguments.callee which you could use instead
of
timedCount in the setTimeout call.
--
/ Johan Sundström, http://ecmanaut.blogspo
t.com/
_______________________________________________
Greasemonkey mailing list
Greasemonkey mozdev.org
http:
//mozdev.org/mailman/listinfo/greasemonkey
|
|
[1-9]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|