[Project_owners] Image prefetching

Todd Ross todd at brainsick.com
Thu Mar 31 15:53:00 EST 2005


Konstantin Svist wrote:
> 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 = ...;
>      }

If you'd like to understand the difference between tmpImage.onload and 
tmpImage.setAttribute("onload", ...) then you should probably read:

http://www.xulplanet.com/ndeakin/article/290?show=c

Todd


More information about the Project_owners mailing list