如何从新窗口保存屏幕截图?

时间:2016-12-10 12:35:11

标签: javascript plugins save window screensaver

Google Chrome插件会在新窗口中打开屏幕截图,但是如何将图像保存在我的计算机上呢?每次再次运行此脚本时,图像如何覆盖自身?代码是用Javascript编写的。

capturePage: function (position, lastCapture) {
var self = this;

setTimeout(function () {
    chrome.tabs.captureVisibleTab(null, {
        "format": "png"
    }, function (dataURI) {
        var newWindow,
            image = new Image();

        if (typeof dataURI !== "undefined") {
            image.onload = function() {
                self.screenshotContext.drawImage(image, 0, position);

                if (lastCapture) {
                    self.resetPage();
                    newWindow = window.open();
                    newWindow.document.write("<style type='text/css'>body {margin: 0;}</style>");
                    newWindow.document.write("<img src='" + self.screenshotCanvas.toDataURL("image/png") + "'/>");

                } else {
                    self.scrollTo(position + self.scrollBy);
                }
            };

            image.src = dataURI;
        } else {
            chrome.tabs.sendMessage(self.tabId, {
                "msg": "showError",
                "originalParams": self.originalParams
            });
        }
    });
}, 300);
},

0 个答案:

没有答案