[Project_owners] Image prefetching

Konstantin Svist fry.kun at gmail.com
Thu Mar 31 07:57:55 EST 2005


WOW, that actually works!
I've been looking for a way of hooking something up to imageloads...
strangely enough, tmpImage.onload = 'alert()' will not work at all...


Anyway, your problem is very simple - some of your images load BEFORE
your JS even gets to tmpImage.setAttribute(...). And since the image
is already loaded, the onload event will not be fired.
To fix it, swap that line with the previous one:
     for ( ... )
     {
         var tmpImage = new Image();
         // This is only for testing purpose
         tmpImage.setAttribute("onload", "alert(this.src);");
         tmpImage.src = ...;
     }



cheers,
Konstantin


On Thu, 31 Mar 2005 11:29:56 +0200, Luca Minuti <lithian at tiscalinet.it> wrote:
> Hi,
> 
> I need to pre-load some images in my firefox extension. Now I have
> a code like this:
> 
>     for ( ... )
>     {
>         var tmpImage = new Image();
>         tmpImage.src = ...;
>         // This is only for testing purpose
>         tmpImage.setAttribute("onload", "alert(this.src);");
>     }
> 
> but with this code I see the alert only for a small amount of images.
> I'm trying to understand how to use the caching system of firefox in a
> more direct way (perhaps with the cache-service component), but
> without success.
> 
> Any one can help me?
> 
> Thanks, Luca.
> 
> _______________________________________________
> Project_owners mailing list
> Project_owners at mozdev.org 
> http://mozdev.org/mailman/listinfo/project_owners 
>


More information about the Project_owners mailing list