Created
April 11, 2017 14:49
-
-
Save examinedliving/b9218ee78587be5090101315da015198 to your computer and use it in GitHub Desktop.
Print from iFrame in current window, and add callbacks for before print, and after print.
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
| (function() { | |
| var beforePrint = function() { | |
| console.log('Functionality to run before printing.'); | |
| }; | |
| var afterPrint = function() { | |
| console.log('Functionality to run after printing'); | |
| }; | |
| var ifr=''//iframe ref; | |
| ifr.focus(); | |
| var cw=''//ifr.contentWindow | |
| if (window.matchMedia) { | |
| var mediaQueryList = cw.matchMedia('print'); | |
| mediaQueryList.addListener(function(mql) { | |
| if (mql.matches) { | |
| beforePrint(); | |
| } else { | |
| afterPrint(); | |
| } | |
| }); | |
| } | |
| cw.onbeforeprint = beforePrint; | |
| cw.onafterprint = afterPrint; | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment