Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to take screen shot of current webpage using Javascript/JQuery?

I was trying to take screen shot of a web page using JavaScript/JQuery. Could you please explain me the code steps I need to follow?

like image 378
user2682340 Avatar asked Aug 14 '13 12:08

user2682340


People also ask

How do I take a screenshot of a website using jQuery?

HTML & Script – Include the jQuery library. Create screenshot() function where initialize html2canvas on the body. By default, html2canvas set the image background color to black if save the screenshot. With the use of background: '#fff' set background white.

How do I take a screenshot of a HTML page?

Please click on the toolbar button (or press Alt+Shift+D combination) to capture the screenshot. You can adjust the screenshot image format from the options page.


1 Answers

The html2canvas2 JavaScript utility is suitable to take a screenshot of a webpage. You have to use three JavaScript libraries:

 1.jquery-1.10.2.min.js
 2.html2canvas.js
 3.jquery.plugin.html2canvas.js

Then call the function capture(), which will give you an HTML5 canvas-based screenshot in new window. It also generates a base64data value of image. It only works in browsers that support HTML5 canvas.

    <script type="text/javascript">
    function capture() {
            html2canvas($('body'),{
                onrendered: function (canvas) {                     
                            var imgString = canvas.toDataURL("image/png");
                            window.open(imgString);                  
            }
        });
   </script>
like image 59
Edward Avatar answered Oct 03 '22 14:10

Edward