This is my code, I am using IE 11 for testing on my project, and the download function did not work. I want to make it download the content as images, please help me find the solution, Thanks.:
$(document).ready(function() {
// Click event handler for the capture button
$('#captureButton').click(function() {
// Get the element you want to capture
var elementToCapture = document.getElementById('contentToCapture');
// Use html2canvas to render the element as a canvas
html2canvas(elementToCapture).then(function(canvas) {
// Convert the canvas to a data URL
var dataUrl = canvas.toDataURL();
// Create a link to trigger the download
var link = document.createElement('a');
link.href = dataUrl;
link.download = 'captured-content.png';
link.click();
});
});
});
/* Styles for the content to be captured */
#contentToCapture {
width: 400px;
padding: 20px;
background-color: lightgray;
}
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js"></script>
<div id="contentToCapture">
<h1>Sample Content</h1>
<p>This is the content you want to capture and save as an image.</p>
</div>
<button id="captureButton">Capture and Save as Image</button>