Take a screenshot of <body> with html2canvas and save img as JS var
I am trying to allow users on my site to click a button to take a screenshot of the current screen (all in the body).
From my research, html2canvas seems like a resource that makes this possible.
My problem is that the documentation does not contain sample code, and I'm struggling to figure out how to do this.
http://html2canvas.hertzen.com/documentation.html
The next SO question ( How to upload a screenshot using html2canvas? ) Leaves me a little confused. I just want to know how to get the image at the moment.
From his code.
$(window).ready(function(){ ('body').html2canvas(); var canvasRecord = new html2canvas(document.body).canvas; //At this point does the .toDataURL method return a png? });
At this point, I am lost where the image is, or even how / when to create it. Do not worry by sending it to the server later.
Any information is appreciated. Thank you (html2canvas even needed?)
Since you are using the html2canvas jQuery plugin, here is an example snippet
var screenshot; $('body').html2canvas({ onrendered: function(canvas) { screenshot = canvas.toDataURL(); //code to process/send the image to server } });
In the above code snippet, html2canvas creates a screenshot of the page.
You can also use PhantomJS to take screenshots of web pages - provided that they are publicly accessible pages, since you will not be able to access pages with server-side login protection; in such situations, only a client solution such as html2canvas will work.