Created
November 19, 2012 14:05
-
-
Save shaliko/4110822 to your computer and use it in GitHub Desktop.
Cross browser print request detection (IE 5+, Firefox 6+, Chrome 9+, and Safari 5.1+ )
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() { | |
var beforePrint = function() { | |
console.log('Functionality to run before printing.'); | |
}; | |
var afterPrint = function() { | |
console.log('Functionality to run after printing'); | |
}; | |
if (window.matchMedia) { | |
var mediaQueryList = window.matchMedia('print'); | |
mediaQueryList.addListener(function(mql) { | |
if (mql.matches) { | |
beforePrint(); | |
} else { | |
afterPrint(); | |
} | |
}); | |
} | |
window.onbeforeprint = beforePrint; | |
window.onafterprint = afterPrint; | |
}()); |
tsukasa-mixer
commented
Aug 5, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment