Home > Article > Web Front-end > Can you take a screenshot of a page using HTML5 Canvas?
Html2Canvas is a JavaScript library that can take screenshots of entire web pages or specific parts. It doesn't take a screenshot, but creates a view based on the page information.
Given below is the sample code. Here, the html2canvas.js script is included in
. Call the html2canvas() method. Returns the base64 value that ultimately creates the image source or image file.<!DOCTYPE html> <html> <head> <script src="html2canvas-master/dist/html2canvas.js"></script> </head> <body> <h1>Take screenshot</h1> <div class="container" id='container' > <imgsrc='images/one.jpg' width='50' height='50'> <imgsrc='images/two.jpg' width='50' height='50'> </div> <input type='button' id='but_screenshot' value='Take screenshot' onclick='screenshot();'><br/> <script> function screenshot(){ html2canvas(document.body).then(function(canvas) { document.body.appendChild(canvas); }); } </script> </body> </html>
The above is the detailed content of Can you take a screenshot of a page using HTML5 Canvas?. For more information, please follow other related articles on the PHP Chinese website!