top

Image Onload function is not called when img source is same as old source

Published 2014-10-27 | (Compatible with SDK 3.5,4.5,5.0,5.1 and 2012,2013,2014 models)

Image reloading differences on 2012 platform

In Maple, Image onload function is called every time image is loaded (even if new image src is same as the old one) however in case of Webkit, Image onload function is not called when the new Image source is same as the old source.

Example

var img = new Image();

img.onload = function() {
    alert("Image loaded");
    ...
}

img.src="./resource/images/forest_of_trees.jpg";
img.src="./resource/images/forest_of_trees.jpg";

In this particular case the results will be different among different platforms:

Webkit
The function on img.onload will be called once
Maple
img.onload will be called twice

Solution

To call Image Onload function every time on both Webkit and Maple, give the image source as empty string first then to the actual source string.

img.src="./resource/images/forest_of_trees.jpg";
img.src="";
img.src="./resource/images/forest_of_trees.jpg";

See also

Refer to files in this package.