Last active
May 9, 2017 07:00
-
-
Save kenchan0130/2b586432ef326bd17aa7f456e14a0401 to your computer and use it in GitHub Desktop.
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
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