Created
October 18, 2017 21:15
-
-
Save wpscholar/acedc387110a1a3389f802372acfbf57 to your computer and use it in GitHub Desktop.
Print part of the screen based on a CSS selector
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 print(selector) { | |
var w = window.open('', '', 'left=0,top=0,width=' + window.width + ',height=' + window.height + ',toolbar=0,scrollbars=0,status=0'); | |
w.document.write('<link rel="stylesheet" type="text/css" href="/path/to.css" />'); | |
w.document.write(document.querySelector(selector).innerHTML); | |
w.document.close(); | |
w.addEventListener('load', function () { | |
w.focus(); | |
w.print(); | |
w.close(); | |
}, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Probably should update this to automatically pull in all the stylesheets from the existing page.