[Greasemonkey] clientWidth not updated after page "greased"

daddydave daddydave at gmail.com
Mon May 8 11:47:40 EDT 2006


I think the problem was that I was trying to refer to variables that are out
of scope in the event handler. I found an example that gives me the idea of
referring  to the img element using the this pointer. The example is old
because it uses the older style Greasemonkey event handling, but I
understand that part I think. :)

http://userscripts.org/scripts/source/3092.user.js

On 5/5/06, daddydave <daddydave at gmail.com> wrote:
>
> Thanks for the superfast reply, Jeremy! and thanks for pointing me in the
> right direction. My first couple of attempts failed, but I'll keep trying
> when I get time.
>
> It sounds like I need to put my fallback icon if the error event fires,
> and I am not sure that I need the load event, since I don't need any further
> action if the image loads ok. If I am only checking the property to see if
> the (modified) image link is broken, it seems like I don't need that
> property since if I get to the error event handler, that means the image
> didn't load.
>
> Is there an example Greasemonkey script that does something similar?
>
>
> On 5/5/06, Jeremy Dunck <jdunck at gmail.com> wrote:
> >
> > On 5/5/06, daddydave <daddydave at gmail.com> wrote:
> > > So it
> > > appears it is picking up the width  *before* the page was greased.
> >
> > No, greasemonkey scripts see the same DOM as DOM Inspector.
> >
> > Setting the img src attribute is asynchronous and your code is winning
> > the race, so your script is picking up the property value before the
> > new image has been fetched and/or rendered, and thus the props you're
> > checking haven't been updated.
> >
> > You should wait for the load to succeed or fail, then proceed.  This
> > also nicely branches your "has/doesn't have" code.  ;-)
> >
> > yourImage.addEventListener('load', function(e) {
> >   //do stuff which depends on successful load
> >   }, true);
> >
> > yourImage.addEventListener ('error', function(e) {
> >   //do stuff which depends on unsuccessful load.
> >   }, true);
> > _______________________________________________
> > Greasemonkey mailing list
> > Greasemonkey at mozdev.org
> > http://mozdev.org/mailman/listinfo/greasemonkey
> >
>
>


More information about the Greasemonkey mailing list