Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

window.print a div

@media print {
  body * {
    visibility: hidden;
  }
  #section-to-print, #section-to-print * {
    visibility: visible;
  }
  #section-to-print {
    position: absolute;
    left: 0;
    top: 0;
  }
}
Comment

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);
}
Comment

window.print() specific div

function printDiv(divName) {
     var printContents = document.getElementById(divName).innerHTML;
     var originalContents = document.body.innerHTML;

     document.body.innerHTML = printContents;

     window.print();

     document.body.innerHTML = originalContents;
}
Comment

window.print() specific div

<div id="printableArea">
      <h1>Print me</h1>
</div>

<input type="button" onclick="printDiv('printableArea')" value="print a div!" />
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript submit form VUE 
Javascript :: javascript merging arrays 
Javascript :: javascript append list to list 
Javascript :: firebase update data 
Javascript :: what is ajax 
Javascript :: discord js check if message author is admin 
Javascript :: lexical scoping in javascript 
Javascript :: javascript stringify blob 
Javascript :: make service singleton angular 
Javascript :: get row data in datatable 
Javascript :: how to get 3rd li using jquery 
Javascript :: ajax error slider revolution 
Javascript :: implement queue using stack javascript 
Javascript :: reacts mos twanted 
Javascript :: use localstorage react hook 
Javascript :: Multiple line string in JS 
Javascript :: side effect, useEffect, return 
Javascript :: nest js crons 
Javascript :: angular 7 selected 
Javascript :: react render children inside parent component 
Javascript :: The reduce() method executes a reducer function on each element of the array and returns a single output value. 
Javascript :: swiper js 
Javascript :: javascript split a string 
Javascript :: selectores de jquery 
Javascript :: chrome.browseraction.getbadgetext 
Javascript :: javascript split method 
Javascript :: get last element in array javascript 
Javascript :: eslint disable line 
Javascript :: html video time 
Javascript :: npm node size 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =