I would like to load some images using JS.
My code:
Expand|Select|Wrap|Line Numbers
- var img=new Image();
- img.onload = function() {f1()};
- img.onerror = function() {f2()};
- img.src='http://example.com/image.gif';
- sett = setTimeout(function() {f3()}, 100000);
- //f3 contains not interesting code and:
- img = null;
- clearTimeout(sett);
1) Some images don't listen to orders from setTimeout and load for 200 and more second. What is wrong with my code? Notice, that it happens only with some images, not all.
2) Images are loading according to status of currently user. In some cases there can appear images which require to login by htpassword to see them. Then user would see a window with fields to login. What can I do to in that case skip this image and avoid showing that window?
Thank you so much for any help.