如何使用html2canvas存储屏幕截图?

Jim*_*Lin 2 javascript jquery html2canvas

我试图使用html2canvas 0.34保存网站的屏幕截图.

但我不知道屏幕截图的保存位置,如何将屏幕截图存储到我的数据库中,或者用新窗口打开图像.

我的代码如下:

<script type="text/javascript">
$('div').html2canvas({
onrendered: function( canvas ) {
var img = canvas.toDataURL();
window.open(img);
}
});
</script>

</head>
<body>         
<h1>Testing</h1>
<div>
<img src='http://25.media.tumblr.com/tumblr_mcc5k9YRli1rt6zh0o1_500.jpg'>
</div>
</body></html>
Run Code Online (Sandbox Code Playgroud)

我想将图像的屏幕截图存储到数据库中或在另一个窗口中打开.

非常感谢你.

小智 5

toDataURL函数只返回图像数据作为字符串,它无法保存它(因为JS无法访问文件系统)

为了保存它,您必须让浏览器将其作为映像加载,或让服务器端脚本处理它.

这应该对你有用 http://www.kevinsookocheff.com/2011/07/27/saving-canvas-data-to-an-image-file-with-javascript-and-php/