Create Dynamic Screenshot of any element on a web page – JavaScript
windwindow.takeScreenShot = function() { html2canvas(document.getElementById("target"), { onrendered: function (canvas) { document.body.appendChild(canvas); }, width:320, height:220 }); }ow.takeScreenShot = function() { html2canvas(document.getElementById("target"), { onrendered: function (canvas) { document.body.appendChild(canvas); }, width:320, height:220 });}
Here is what the above code is Doing:
1. It’s creating a function called takeScreenShot()
2. It’s using the html2canvas library to take a screenshot of the element with the id “target”
3. It’s appending the screenshot to the body of the page
4. It’s setting the width and height of the screenshot to 320×220
5. It’s assigning the function to the ow.takeScreenShot() variable
Now, let’s see how we can use this function to take a screenshot of the page.