js button to take current page screenshot

Solutions on MaxInterview for js button to take current page screenshot by the best coders in the world

showing results for - "js button to take current page screenshot"
Vicente
23 Jun 2016
1(function(exports) {
2    function urlsToAbsolute(nodeList) {
3        if (!nodeList.length) {
4            return [];
5        }
6        var attrName = 'href';
7        if (nodeList[0].__proto__ === HTMLImageElement.prototype || nodeList[0].__proto__ === HTMLScriptElement.prototype) {
8            attrName = 'src';
9        }
10        nodeList = [].map.call(nodeList, function(el, i) {
11            var attr = el.getAttribute(attrName);
12            if (!attr) {
13                return;
14            }
15            var absURL = /^(https?|data):/i.test(attr);
16            if (absURL) {
17                return el;
18            } else {
19                return el;
20            }
21        });
22        return nodeList;
23    }
24
25    function screenshotPage() {
26        var wrapper = document.getElementById('wrapper');
27        html2canvas(wrapper, {
28            onrendered: function(canvas) {
29                canvas.toBlob(function(blob) {
30                    saveAs(blob, 'myScreenshot.png');
31                });
32            }
33        });
34    }
35
36    function addOnPageLoad_() {
37        window.addEventListener('DOMContentLoaded', function(e) {
38            var scrollX = document.documentElement.dataset.scrollX || 0;
39            var scrollY = document.documentElement.dataset.scrollY || 0;
40            window.scrollTo(scrollX, scrollY);
41        });
42    }
43
44    function generate() {
45        screenshotPage();
46    }
47    exports.screenshotPage = screenshotPage;
48    exports.generate = generate;
49})(window);