Created
November 27, 2012 14:24
-
-
Save alloyking/4154468 to your computer and use it in GitHub Desktop.
Check if file exists
This file contains 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 doesFileExist(urlToFile) | |
{ | |
var xhr = new XMLHttpRequest(); | |
xhr.open('HEAD', urlToFile, false); | |
xhr.send(); | |
if (xhr.status == "404") { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
//////// | |
var result = doesFileExist("http://www.someplace.com/myimage.png"); | |
if (result == true) { | |
// yay, file exists! | |
} else { | |
// file does not exist! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment