How to take screenshots of web pages (html2canvas)

零下一度
Release: 2017-05-03 16:05:14
Original
2791 people have browsed it

html2canvas is a pretty good JavaScript class library. It uses some new features of html5 and css3 to realize the function of taking screenshots of web pages on the client. html2canvas achieves the function of taking screenshots of the page by obtaining the DOM and style information of the elements of the page and rendering it into a canvas image. Because each browser renders pages differently, the images generated are also different. Although it is still in the development stage, it is still worth looking forward to. It does not require any rendering from the server, the entire image is created in the client browser. When the browser does not support Canvas, Flashcanvas or ExplorerCanvas technology will be used instead.
github:github.com/niklasvh/html2canvas
The code is as follows:

<!DOCTYPE html>
<html>
  <head>
    <title>HTML5实现网页截屏</title>
    <script src="http://cdn.bootcss.com/jquery/3.0.0-beta1/jquery.min.js"></script>
    <script src="http://cdn.bootcss.com/html2canvas/0.5.0-beta4/html2canvas.js"></script>
    <script>
      function taoge(){
        html2canvas($(&#39;#xttblog&#39;), {
          onrendered: function(canvas) {
            // canvas 是最后一个渲染的<canvas> 元素
            $(&#39;#btn&#39;).attr( &#39;href&#39; , canvas.toDataURL() ) ;
            $(&#39;#btn&#39;).attr( &#39;download&#39; , &#39;xttblog.png&#39; ) ;
          }
        });
      }
    </script>
  </head>
  <body>
    <p id="xttblog">
      <img src="http://www.xttblog.com/wp-content/uploads/2016/03/123.png"/>
      <p>业余草,做专业的IT学习交流网站</p>
      <p>QQ群:135430763</p>
      <p>原文地址:http://www.xttblog.com/?p=261</p>
      <a href="" id="btn" onclick="taoge();">截图</a>
    </p>
  </body>
</html>
Copy after login

The above is the detailed content of How to take screenshots of web pages (html2canvas). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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