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

WBOY
Release: 2023-09-07 10:45:08
forward
686 people have browsed it

你能使用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>
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!