网页截图

0

使用JS插件html2canvas.js将网页转为canvas

html2canvas(document.body, {
    onrendered : function(canvas) {
        // 操作画布对象
    }
});

然后将画布转为图片:

var image = canvas.toDataURL("image/png");

如果需要下载:

var $download = $('<a id="download"></a>');    
$download.appendTo("body");     
var image = canvas.toDataURL("image/png").replace("image/png", "image/octet-stream;");    
$download.attr("href", image);    
$download.attr("download", "image.png"); // 下载文件名
// $download.trigger("click"); // jQuery模拟点击事件无效    
var event = document.createEvent("MouseEvents"); // 模拟点击事件
event.initMouseEvent("click", true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);    
$download[0].dispatchEvent(event);

DEMO地址:http://www.acgist.com/demo/html-canvas/index.html