Skip to content

Instantly share code, notes, and snippets.

@riix
Created July 24, 2012 06:45
Show Gist options
  • Save riix/3168447 to your computer and use it in GitHub Desktop.
Save riix/3168447 to your computer and use it in GitHub Desktop.
이미지 URL 체크, Check if an image url is valid with javascript/jquery
function imageTest(url) {
var imageTarget = $('#urlImageTester');
imageTarget.prop('src', url);
var props = ['naturalHeight', 'fileCreatedDate'];
var tests = [];
var answer;
for (i in props) {
tests.push(imageTarget.prop(props[i]));
}
if ($.browser.msie) {
(tests[1] == 'undefined') ? answer = false : answer = true;
} else {
(tests[0] == 0) ? answer = false : answer = true;
}
return answer;
}
// create an image and hide it with css, the id used here us urlImageTester
// the function uses jquery to check if your using IE or another browser and proforms tests dependant on the browser.
// the function returns false if the url passed to it, is broken or invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment