Answers for "js div print"

2

html print div

function 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(document.getElementById(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;
}
Posted by: Guest on April-23-2021
0

window.print div

// It's really that simple. Make sure the dimensions of 'elem' 
// fit the width of the PDF layout you're looking for.
// FYI: IE, Edge, Chrome, Firefox, etc. all have different dimensions when 
// they print.
function PrintElem(elem: HTMLElement)
{
    var mywindow = window.open('', 'PRINT', 'height=400,width=600');

    mywindow.document.write(elem.innerHTML);

    mywindow.document.close(); // necessary for IE >= 10
    mywindow.focus(); // necessary for IE >= 10*/

    mywindow.print();
  	setTimeout(() => {
        // Without the timeout, the window seems to close immediately.
    	mywindow.close();    	
    }, 250);
}
Posted by: Guest on November-05-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language