Created
September 14, 2016 02:53
-
-
Save bkawk/427d80df690a4697623bf111ae2fc441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getImage(url){ | |
return new Promise(function(resolve, reject){ | |
var img = new Image() | |
img.onload = function(){ | |
resolve(url) | |
} | |
img.onerror = function(){ | |
reject(url) | |
} | |
img.src = url | |
}) | |
} | |
getImage('doggy.jpg').then(function(successurl){ | |
document.getElementById('doggyplayground').innerHTML = '<img src="' + successurl + '" />' | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment