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

html2canvas - How To Copy Canvas As Image To Clipboard Using Javascript Programmatically - Stack Overflow

programmeradmin3浏览0评论

I already use html2canvas.js to take a screenshot of a specific div, now I wonder if I could use js to copy the canvas element as an image to clipboard, then user can just click to have an image of what they want on their clipboard, all they need to do is just paste it.

Codepen Demo

I already use html2canvas.js to take a screenshot of a specific div, now I wonder if I could use js to copy the canvas element as an image to clipboard, then user can just click to have an image of what they want on their clipboard, all they need to do is just paste it.

Codepen Demo

Share Improve this question asked Oct 27, 2016 at 7:03 AlessiaAlessia 96911 silver badges16 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

It work only on https or localhost:

    function getScreenShot(Src){
        let src = document.getElementById(Src);
        html2canvas(src).then(function(canvas) {
          document.getElementById("explain-scr").appendChild(canvas);
          canvas.toBlob(function(blob) {
            navigator.clipboard
              .write([
                new ClipboardItem(
                  Object.defineProperty({}, blob.type, {
                    value: blob,
                    enumerable: true
                  })
                )
              ])
              .then(function() {
                  // do something
              });
          });
        });
      }
发布评论

评论列表(0)

  1. 暂无评论