Skip to content

Instantly share code, notes, and snippets.

@esnho
Created December 17, 2022 16:46
Show Gist options
  • Save esnho/e166d512d2077ec422740f11edfb0f4c to your computer and use it in GitHub Desktop.
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
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