Below is my code that I execute:
<head>
<script>
function uploadFile() {
console.log('here');
var x = document.getElementById('img');
console.log(x.files);
var _URL = window.URL || window.webkitURL;
var file = x.files.item(0);
var img = new Image();
img.src = _URL.createObjectURL(file);
img.onload = function () {
alert("alert1 : this alert should come before");
alert(this.width + " " + this.height);
}
alert("alert2: this alert should come later");
}
</script>
</head>
<body>
<input type='file' id='img' accept="image/*"/>
<input type='submit' value='Upload' onclick='uploadFile()'/>
</body>
<html>
I want alert1 to be displayed before alert2.
Currently, first alert2 is displayed before alert1.