title: Check if a image exists with a given URL - JavaScript
body: <p>I'm trying to check if an image exists given a url using javascript, but my code is not working. Thanks!</p>
  
  <p>Here's my function :</p>
  
  <pre><code>function verifyImageURL(url, callBack) {
    var img = new Image();
    img.src = url;
    img.onload = function () {
          callBack(true);
    };
    img.onerror = function () {
          callBack(false);
    };
  }
  </code></pre>
  
  <p>And Here's how I call it:</p>
  
  <pre><code>var url = "http://greenstyle.com.br/wp-content/uploads/2012/09/Tucano-imagem-Silvia-Kochen-Wordpress.jpg";
  verifyImageURL(url, function (imageExists) {
          if (imageExists === true) {
              alert("Image Exists");
          } else {
              alert("Image does not Exist");
          }
      });
  </code></pre>