In below code I have 3 alert()
and I want to these alerts respectively fired. first alert(1)
, second alert(2)
and then alert(3)
but now because of img.onload()
function alert(3)
fired before alert(2)
.
var _URL = window.URL || window.webkitURL;
$("#file").change(function(e) {
var file, img;
if ((file = this.files[0])) {
img = new Image();
alert(1)
img.onload = function() {
alert(2)
};
alert(3)
img.src = _URL.createObjectURL(file);
}
});
Is there any way to do this?