Skip to content

Instantly share code, notes, and snippets.

@dubbs
Created January 7, 2013 19:53
Show Gist options
  • Save dubbs/4477834 to your computer and use it in GitHub Desktop.
Save dubbs/4477834 to your computer and use it in GitHub Desktop.
Cross browser print request detection
(function() {
var beforePrint = function() {
console.log('before');
};
var afterPrint = function() {
console.log('after');
};
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
window.onbeforeprint = beforePrint;
window.onafterprint = afterPrint;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment