最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I store the screenshot using html2canvas? - Stack Overflow

programmeradmin4浏览0评论

I am trying to save the screenshot of website using html2canvas 0.34.

But I don't know where the screenshot be saved, how to store the screenshot into my db, or open the the image with a new window.

My code is below:

<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='.jpg'>
</div>
</body></html>

I want to store the screenshot of the image into database or open in another windows.

Thank you very much.

I am trying to save the screenshot of website using html2canvas 0.34.

But I don't know where the screenshot be saved, how to store the screenshot into my db, or open the the image with a new window.

My code is below:

<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./tumblr_mcc5k9YRli1rt6zh0o1_500.jpg'>
</div>
</body></html>

I want to store the screenshot of the image into database or open in another windows.

Thank you very much.

Share Improve this question asked Oct 23, 2012 at 10:09 Jimmy LinJimmy Lin 1,5016 gold badges27 silver badges46 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

The toDataURL function only returns the image data as a string, it is incapable of saving it (as JS don't have access to the file system)

In order to save it you ether have to let your browser load it as an image, or let a server side script handle it.

this should be useful to you http://www.kevinsookocheff./2011/07/27/saving-canvas-data-to-an-image-file-with-javascript-and-php/

   var data = canvas.toDataURL();
-----------------For Downloading Imgage in Chrome (just 4 testing)-------------------------
/* var save = document.createElement('a');
        save.href = data;
        save.target = '_blank';
        save.download = 'fileName';

        var event = document.createEvent('Event');
        event.initEvent('click', true, true);
        save.dispatchEvent(event);
        (window.URL || window.webkitURL).revokeObjectURL(save.href);*/
//---------------------------------
发布评论

评论列表(0)

  1. 暂无评论