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 :: call url many times 
Javascript :: JS call url many times 
Javascript :: Simple Email Validation, Case Insensitive, w/ All Valid Local Part Characters (whatever tf that means to you...) - Regex 
Javascript :: shopify hover effect 
Javascript :: jquery replacechild 
Javascript :: js react change slide by touch event 
Javascript :: vue get key inside component 
Javascript :: react native asyncstorage mergeItem example 
Javascript :: Error: Node Sass version 7.0.1 is incompatible with ^4.0.0. angular 
Javascript :: the specified value cannot be parsed or is out of range javascript 
Javascript :: jquery ui music player 
Javascript :: what is the equivalent of cascade on delete in mongoose 
Javascript :: email validation in form using javascript 
Javascript :: how to get the total price of all product in cart using react 
Javascript :: Private slots are new and can be created via Instance and static private fields 
Javascript :: recharts area chart 
Javascript :: p5 js stop video camera capture 
Javascript :: sails sqlite3 
Javascript :: setinterval clearinterval querySelector until render 
Javascript :: Quitar objetos duplicados 
Javascript :: Example of Promise.any() and AggregateError in es12 
Javascript :: show route between markers google maps javascript 
Javascript :: image opacity reduce js 
Javascript :: Write File to the Operating System with NodeJS 
Javascript :: salesforce js merge object 
Javascript :: How do you convert VARCHAR to TIMESTAMP 
Javascript :: Insert tag in XML text for mixed words 
Javascript :: borrar line vscode 
Javascript :: react Colored rating 
Javascript :: nestjs mongoose ClassSerializerInterceptor not working 
ADD CONTENT
Topic
Content
Source link
Name
5+4 =