0

Is it possible somehow to check is image loaded without function .load() or onLoad? Problem is that the webkit-like browsers doesn't work properly with this function.

UPDATE: Problem is in http://en.wikipedia.org/wiki/Motion_JPEG - load fires only once otherwise stream is going and loading new images.

5
  • 2
    The .complete boolean property will tell you if the image is loaded. So if ( img.complete ) { ... }. (Note, though, that it probably isn't implemented in IEold.) Commented Sep 7, 2012 at 13:16
  • Webkit browsers support the "load" event for images. What do you mean? Commented Sep 7, 2012 at 13:21
  • They do not fire the event if the image is coming from cache. Commented Sep 7, 2012 at 13:21
  • @SoonDead Yes. Browsers generally behave like that. Commented Sep 7, 2012 at 13:23
  • If I remember correctly IE-s don't. Commented Sep 7, 2012 at 13:24

2 Answers 2

4

You can check img.width : it's 0 if it's not loaded.

But I'm sure you can use onload (all low cap) on webkit browsers too :

 img.onload=function(){ console.log('loaded!'); }; img.src='something'; 

Beware a frequent error : you have to set the src after you set the onload, or the onload callback won't be called if the image is in cache.

Demonstration : tested on Chrome, which is webkit based

Sign up to request clarification or add additional context in comments.

1 Comment

You should have said it immediately. Your title was about "image loaded" while "mjpeg" is a video format.
3

I used this https://github.com/desandro/imagesloaded in a project and it worked fine for me

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.