title: How to upload a screenshot using html2canvas?
body: <p>Using <a href="http://html2canvas.hertzen.com/" rel="nofollow noreferrer">html2canvas</a> how can I save a screen shot to an object? I've been exploring the demos, and see that the function to generate the screenshot is generated as follows:</p>
  
  <pre><code>$(window).ready(function() {
    ('body').html2canvas();       
  });
  </code></pre>
  
  <p>What I've tried doing is </p>
  
  <pre><code>$(window).ready(function() {
    canvasRecord = $('body').html2canvas(); 
    dataURL = canvasRecord.toDataURL("image/png");
    dataURL = dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
    upload(dataURL);
  
  });
  </code></pre>
  
  <p>And, I then pass it to my <code>upload()</code> function. The problem I am having, is I can't figure out where the screenshot is being made in the <code>html2canvas()</code> library or what function returns it. I've tried converting the canvas object using <a href="https://stackoverflow.com/a/934925/258755">this</a> answer from SO (though I'm not certain I need to do this).</p>
  
  <hr>
  
  <p>I just asked a <a href="https://stackoverflow.com/questions/9249659/uploading-a-png-to-imgur-using-javascript">question</a> on how to upload a file to <a href="http://imgur.com/" rel="nofollow noreferrer">imgur</a>, and the answers there (particularly @bebraw's) help me to understand what I need to do.</p>
  
  <p>The <code>upload()</code> function is from the Imgur example api help:</p>
  
  <pre><code>function upload(file) {
     // file is from a &lt;input&gt; tag or from Drag'n Drop
     // Is the file an image?
     if (!file || !file.type.match(/image.*/)) return;
  
     // It is!
     // Let's build a FormData object
     var fd = new FormData();
     fd.append("image", file); // Append the file
     fd.append("key", "mykey"); // Get your own key: http://api.imgur.com/
  
     // Create the XHR (Cross-Domain XHR FTW!!!)
     var xhr = new XMLHttpRequest();
     xhr.open("POST", "http://api.imgur.com/2/upload.json"); // Boooom!
     xhr.onload = function() {
        // Big win!
        // The URL of the image is:
        JSON.parse(xhr.responseText).upload.links.imgur_page;
     }
  
     // Ok, I don't handle the errors. An exercice for the reader.
     // And now, we send the formdata
     xhr.send(fd);
  }
  </code></pre>