Created
March 12, 2019 09:24
-
-
Save zeshanshani/de899d2b02414e7f092761d3d9ae6e3e to your computer and use it in GitHub Desktop.
This code prints an image on the page.
This file contains hidden or 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
| /** | |
| * Image Sourec to Print | |
| * | |
| * Usage: | |
| * | |
| * imgPrint( $('img').attr('src') ); | |
| * | |
| * @param {string} source source of the image | |
| */ | |
| function imgSourceToPrint( source ) { | |
| return "<html><head><script>function step1(){\n" + | |
| "setTimeout('step2()', 10);}\n" + | |
| "function step2(){window.print();window.close()}\n" + | |
| "</scri" + "pt></head><body onload='step1()'>\n" + | |
| "<img src='" + source + "' /></body></html>"; | |
| } | |
| /** | |
| * Image Print | |
| * @param {string} source source of the image | |
| */ | |
| function imgPrint( source ) { | |
| Pagelink = "about:blank"; | |
| var pwa = window.open( Pagelink, "_new" ); | |
| pwa.document.open(); | |
| pwa.document.write( imgSourceToPrint( source ) ); | |
| pwa.document.close(); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment