Created
June 27, 2019 23:41
-
-
Save up209d/cd8191c844340fd0dcd1f0704e6d224f to your computer and use it in GitHub Desktop.
utils.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Convert Image to binary to arrayBuffer to clipboard (not work) | |
var canvasDataUrl = ((document.getElementsByClassName("canvasjs-chart-canvas"))[0]).toDataURL("image/png"); | |
fetch(canvasDataUrl) | |
.then(res => res.arrayBuffer()) | |
.then(arrayBuffer => { | |
const uint8Array = new Uint8Array(arrayBuffer); | |
document.addEventListener('copy', function(e) { | |
var str = ''; | |
uint8Array.forEach(function(d) { | |
str += String.fromCharCode(d) | |
}) | |
//You can ignore setting third parameter value | |
e.clipboardData.setData('text', str, true); | |
console.info('data copied'); | |
e.preventDefault(); | |
}); | |
document.execCommand('copy'); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://jsfiddle.net/gq2uk1wd/