Is there a way to make a screenshot using javascript?


I would like to know if there is any way to do a screenshot using javascript , I have found how to make a screenshot of a url but what I need is to capture the screen that the user is viewing.

Thanks in advance.

asked by ftorres 01.01.2017 в 22:19

1 answer


Making screenshot is a native behavior of the operating system, therefore, from your browser you can not access it. What you can do is transform the HTML document to canvas and later to a URL by means of the toDataURL() function.

The following example makes use of the library html2canvas .

html2canvas(document.body, {
  onrendered (canvas) {
    var link = document.getElementById('download');;
    var image = canvas.toDataURL();
    link.href = image; = 'screenshot.png';
<!DOCTYPE html>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
  Hola, éste es un test para tomar una screenshot y descargarla.
  <a id="download">Tomar screenshot y descargar</a>

  <script src=""></script>

If you want to be downloaded automatically just call the function click on the link ( ).

answered by 01.01.2017 / 22:55