If you just want to have screenshot of a div, you can do it like this
Here is a code to take a screenshot of div
<!DOCTYPE html>
<html>
<head>
<title>Take Screen Shot</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
</head>
<body>
<div id="screenshot">
<h1>Take a screenshot of that div</h1>
Hello World......
</div>
<button onclick="screenshot()">Make Screen Shot</button>
<div id="mycanvas"></div>
<script type="text/javascript">
function screenshot() {
var element = document.getElementById('screenshot');
window.scrollTo(0,0);
html2canvas(element, {
width: 1200,
height: 2000,
onrendered:function(canvas) {
canvas.setAttribute("id", "mycanvas");
var dataURL = canvas.toDataURL("image/png");
//console.log(dataURL);
window.open(dataURL);
}
});
}
</script>
</body>
</html>
Here is a screen shot
For more information Click Here


Comments
Post a Comment