Home  >  Article  >  Web Front-end  >  Can you take a screenshot of a page using HTML5 Canvas?

Can you take a screenshot of a page using HTML5 Canvas?

WBOY
WBOYforward
2023-09-07 10:45:08659browse

你能使用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.

Example

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=&#39;container&#39; >
         <imgsrc=&#39;images/one.jpg&#39; width=&#39;50&#39; height=&#39;50&#39;>
         <imgsrc=&#39;images/two.jpg&#39; width=&#39;50&#39; height=&#39;50&#39;>
      </div>
      <input type=&#39;button&#39; id=&#39;but_screenshot&#39; value=&#39;Take screenshot&#39; onclick=&#39;screenshot();&#39;><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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete