Skip to content

Instantly share code, notes, and snippets.

@hirokiky
Created November 7, 2017 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirokiky/bce929937e7bfca2af53b523e9078db6 to your computer and use it in GitHub Desktop.
Save hirokiky/bce929937e7bfca2af53b523e9078db6 to your computer and use it in GitHub Desktop.
Taking Screen Shots of main window from child popup window.
<html>
<head>
<script src="/js/html2canvas.min.js"></script>
</head>
<body>
<button class="screen-shot">ScreenShot</button>
<script>
var btn = document.querySelector('.screen-shot');
btn.addEventListener("click", function() {
if (!window.opener || window.opener.closed) {
window.alert('no opener window');
return false;
}
html2canvas(window.opener.document.body, {
allowTaint: true,
useCORS: true,
}).then(function(canvas) {
document.body.appendChild(canvas);
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment