Created
December 8, 2016 15:07
-
-
Save miguel-leon/d0a24f4c638211cb7c90314708355a50 to your computer and use it in GitHub Desktop.
Send a pdf embedded to print
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
function printPdf(url) { | |
var frame = document.createElement('iframe'); | |
frame.setAttribute('style', 'display:none;'); | |
frame.setAttribute('src', url); | |
var element = document.body.appendChild(frame); | |
element.addEventListener('load', function () { | |
element.contentWindow.print(); | |
document.addEventListener('focus', focusEventListener, true); | |
}); | |
function focusEventListener() { | |
document.body.removeChild(element); | |
document.removeEventListener('focus', focusEventListener, true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment