Created
July 24, 2012 06:45
-
-
Save riix/3168447 to your computer and use it in GitHub Desktop.
이미지 URL 체크, Check if an image url is valid with javascript/jquery
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 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