Skip to content

Instantly share code, notes, and snippets.

@up209d
Created June 27, 2019 23:41
Show Gist options
  • Save up209d/cd8191c844340fd0dcd1f0704e6d224f to your computer and use it in GitHub Desktop.
Save up209d/cd8191c844340fd0dcd1f0704e6d224f to your computer and use it in GitHub Desktop.
utils.js
// 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');
})
@up209d
Copy link
Author

up209d commented Jun 28, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment