Test title
HTML
<div id="forPrint">
<div id="printable">
<div class="box">
Lorem ispum sit amet.
</div>
</div>
</div>
<button type='button' onClick="onPrint('google.com')">
Click
</button>
JavaScript
function onPrint(url) {
this.mode = 'print';
const mywindow = window.open('', 'PRINT', 'height=400,width=600');
const styles = `html,
body {
height: 100% !important;
width: 100%!important;
}
h1 {
color: #1c7430;
}
#printable {
display: flex!important;
justify-content: center!important;
align-items: center!important;
height: 100% !important;
width: 700px!important;
}
.box {
width: 100px!important;
height: 100px!important;
background: green!important;
}`
mywindow.document.write(`<html><head><title>${document.title}</title>`);
mywindow.document.write(`<style>${styles}</style>`)
mywindow.document.write('</head><body >');
mywindow.document.write(`<h1> www.${url}</h1>`);
mywindow.document.write(document.getElementById('forPrint').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;
}