Created
December 17, 2022 16:46
-
-
Save esnho/e166d512d2077ec422740f11edfb0f4c to your computer and use it in GitHub Desktop.
Print an element of the page using a new window, useful to save page snippet from the developers console
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
PrintElem = (elem) => | |
{ | |
var mywindow = window.open('', 'PRINT', 'height=400,width=600'); | |
mywindow.document.write('<html><head><title>' + document.title + '</title>'); | |
mywindow.document.write('</head><body >'); | |
mywindow.document.write('<h1>' + document.title + '</h1>'); | |
mywindow.document.write(elem.innerHTML); | |
mywindow.document.write('</body></html>'); | |
mywindow.document.close(); // necessary for IE >= 10 | |
mywindow.focus(); // necessary for IE >= 10*/ | |
mywindow.print(); | |
mywindow.close(); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment