Skip to content

Instantly share code, notes, and snippets.

@kenchan0130
Last active May 9, 2017 07:00
Show Gist options
  • Save kenchan0130/2b586432ef326bd17aa7f456e14a0401 to your computer and use it in GitHub Desktop.
Save kenchan0130/2b586432ef326bd17aa7f456e14a0401 to your computer and use it in GitHub Desktop.
var e = document.createElement('script');
e.type = 'text/javascript';
e.charset='UTF-8';
e.src = 'https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js';
document.body.appendChild(e);
function repFun() {
if (typeof html2canvas !== 'function') {
setTimeout(repFun);
} else {
html2canvas(document.body, {
onrendered: function(canvas) {
var imageType = 'image/png';
var image = canvas.toDataURL(imageType);
var bin = atob(image.replace(/^.*,/, ''));
var buffer = new Uint8Array(bin.length);
for (var i = 0; i < bin.length; i++) {
buffer[i] = bin.charCodeAt(i);
}
var blob = new Blob([buffer.buffer], {
type: imageType
});
var blobUrl = URL.createObjectURL(blob);
window.location = blobUrl;
}
});
}
};
repFun();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment