I have following code to take the screenshot of 'target' division. I found this on a website. But I do not know how " onrendered:function() " works. I want to ask how "onrendered" is used ? And what difference does it make if I do not add " onrendered : " ?
$('#target').html2canvas({onrendered: function (canvas) {var img = canvas.toDataURL("image/jpg"); } });
Best Answer
onrendered
Gets fired when the final canvas is done converting, and renders. So basically there's a very small amount of time between converting it from html to a canvas.
Here's some documentation I found about html2canvas.
The 'onrendered' event in JavaScript allows you to execute a function after an element has been rendered on the page. This event is commonly used in situations where you need to perform a certain action once an element has finished rendering, such as updating the UI or manipulating the DOM.
To use the 'onrendered' event, you first need to identify the element you want to target. You can do this by using the 'getElementById' method or any other method that allows you to select the desired element.
Once you have the element, you can assign the 'onrendered' event to it by using the 'addEventListener' method. This method takes two arguments: the event name ('onrendered') and the function you want to execute when the event occurs.
Here's an example of how to use the 'onrendered' event:
const element = document.getElementById('myElement');element.addEventListener('onrendered', () => {// Your code here});