Skip to content

Instantly share code, notes, and snippets.

@CreatiCoding
Last active January 27, 2021 09:18
Show Gist options
  • Save CreatiCoding/8e8bc93399b8f78442036ae74660c537 to your computer and use it in GitHub Desktop.
Save CreatiCoding/8e8bc93399b8f78442036ae74660c537 to your computer and use it in GitHub Desktop.
[javascript] Div to html in chrome
function printElement(ele, w = 800, h = 400){
var divContents = document.querySelector(ele).innerHTML;
var printWindow = window.open('', '', `height=${h},width=${w}`);
printWindow.document.write('<html><head><title>NoName</title>');
printWindow.document.write('</head><body >');
printWindow.document.write(divContents);
printWindow.document.write('</body></html>');
printWindow.document.close();
printWindow.print();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment