Skip to main content

Posts

Showing posts with the label screenshot

Capturing the screenshot of a web-page from your web app (using html2Canvas)

A few months ago, I had to add a feature to this web app at work that would enable the users to get a screenshot of the page they are on. When I was given this problem to solve, I thought surely someone must have solved this problem? so I started looking for a library that would help me achieve this. After a bit of searching I came across the html2canvas library which is awesome and it really does get the job done. I am not going to get into details about how the html2canvas library works, I think it's documentation does a good job of it. Anyway my javascript code to capture the screenshot was something like this. function getScreenshot(callbackFunc){ var content = document.querySelectorAll("divToCapture")[0]; setTimeout(function(){screenCap();},0); function screenCap(){ html2canvas(content, { onrendered: function(canvas) { callbackFunc(canvas.toDataURL()); } }); } } So the above function is pr...