Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.print() print all div content without scrollbar

i want to print web page with javascript function window.print()

the page include div with scroll bar

But printing is displayed only part of the div

I tried to add to css

@media print
{
 .myDiv
  { 
    height:100%;
  }

}

but it not work,

i want to show all div content without scroll bar how i do it?

like image 893
El_L Avatar asked Dec 20 '22 01:12

El_L


1 Answers

This method will let you print any arbitrary div.

Using jQuery:

function print(selector) {
    var $print = $(selector)
        .clone()
        .addClass('print')
        .prependTo('body');

    //window.print() stops JS execution
    window.print();

    //Remove div once printed
    $print.remove();
}

And some CSS:

body, html {
    width: 100%;
    height: 100%;
}

.print {
     position: fixed;
     overflow: auto;
     width: 100%;
     height: 100%;
     z-index: 100000; /* CSS doesn't support infinity */

     /* Any other Print Properties */
}
like image 58
Brian Peacock Avatar answered Dec 28 '22 09:12

Brian Peacock