img.onload = this.getLoadComplete();
You're invoking getLoadComplete()
immediately, and assigning its return value to img.onload
. You probably want this:
img.onload = this.getLoadComplete;
That is, set img.onload
to the function itself, not its return value.
You don't need to do anything special in onerror
; the onload
handler will still be set to getLoadComplete
, and when you modify the src
in your onerror
handler, it will invoke onload
after the fallback image is loaded.