Is there a way to make a screenshot but only a "div" using javascript?

0

I would like to know if there is any way to make a screenshot using javascript, I found how to make a screenshot of the whole screen but what I need is to capture only what is contained in a div.

Maybe you can help me modify the script, thanks in advance. html2canvas is used. The script is as follows:

html2canvas(document.body, {   onrendered (canvas) {
    var link = document.getElementById('descargar');;
    var image = canvas.toDataURL();
    link.href = image;
    link.download = 'carputarpantalla.png';   }  });
    
asked by Juan Carlos 05.06.2018 в 19:01
source

1 answer

0

You should only place your div instead of the body

html2canvas(document.querySelector("#tu-div")).then(canvas => {         
    let image = canvas.toDataURL();
    let link = document.getElementById('descargar');
    link.href = image;
    link.download = 'carputarpantalla.png';
});
    
answered by 08.06.2018 в 23:06