0

I am experiencing a strange bug in PhoneGap on Android 4.4, for which I couldn't find any solution online. In my app, I am loading a lot of different images from a remote server, and as the user navigates back and forth, new images are loaded on each page (4 at a time, to be specific, through jQuery-generated html). After having navigated back and forth for a little while, some images will randomly not show up and instead show the typical "broken image" icon.

Now, here comes the strange part: I have been following the instructions at jQuery/JavaScript to replace broken images and done a few tests of my own. In conclusion, the naturalWidth and naturalHeight parameters report the right sizes of the images, and complete reports true for all images. Therefore, the solutions mentioned in the above SO thread don't work at all. Changing the image src doesn't help, either with or without a setTimeout (I tried adding the current timestamp as a parameter to the image path as well).

Did anyone else encounter this issue at all, or am I going crazy here? :)

EDIT: By the way, no error is ever reported. Therefore, no error handler is called when loading the image, making it useless to solve the problem with the already suggested methods (see the link above).

Community
  • 1
  • 1
markj
  • 137
  • 10

1 Answers1

0

This is how i handle error images,

<img src="images/imageName.jpg" onError="onErrorFunc(this);"  alt="&nbsp;" />

function onErrorFunc(elem){
    var imgUrl = "https://alternative-image";
    elem.onerror = function (){
        elem.src='images/noimage.jpg';
    }
    elem.src=imgUrl;
}

Hope it helps!

locknies
  • 1,345
  • 3
  • 15
  • 36
  • Thank you for your answer. As I mentioned, though, this is one of the things I already tried (see the link I mentioned). In my case, it doesn't report an error and therefore doesn't call my error handler. I don't know what to read from this, but it looks like it's not necessarily a server issue. – markj Jan 14 '15 at 13:04
  • What's even more strange is that it shows the "broken image" icon, but it doesn't call my error handler. Instead, it just reports back that the image loaded successfully. Thank you, Android, you're being very helpful.. – markj Jan 14 '15 at 13:09