Created
December 9, 2016 06:49
-
-
Save Uysim/12e56694410cb47d8d5c6ddbc958a170 to your computer and use it in GitHub Desktop.
Background print is use for print page without open in tab. Its purpose use for print PDF.
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
# new BackgroundPrint('http://book.pdf').print() | |
class window.BackgroundPrint | |
constructor: (url)-> | |
@url = url | |
print: -> | |
@_createFrame() | |
@_handleFrameLoad() | |
@_loadFrame() | |
_createFrame: -> | |
@iframe = document.createElement('iframe') | |
document.body.appendChild @iframe | |
@iframe.style.display = 'none' | |
_handleFrameLoad: -> | |
service = @ | |
@iframe.onload = -> | |
setTimeout((-> | |
service.iframe.focus() | |
service.iframe.contentWindow.print() | |
), 1) | |
_loadFrame: -> | |
@iframe.src = @url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment