Skip to content

Instantly share code, notes, and snippets.

@dukedave dukedave/page.css
Created Feb 1, 2016

Embed
What would you like to do?
Custom print DOM
@media print {
body>:not(.printme) {
display: none;
}
}
@media not print{
.printme {
display: none;
}
}
(function() {
var beforePrint = function(e) {
$('body').append('<div class="printme"><p>HELLO PRINTER</p></div>');
};
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;
}())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.