Pearl
Pearl

Reputation: 9445

Entire page is printing in IE when using jQuery plugin

HTML

<div id="printDiv">
<!-- content Here -->
</div>
<input type="button" value="Print" onclick="printDiv()"/>

JQuery

function printDiv()
{
  $("#printDiv").print();
}

This is prinitng the specific div when using Mozilla Firefox but when using IE (version 10), it is printing the entire page.

I'm using this jQuery plugin.

jQuery.print.js

Please help me.

Upvotes: 0

Views: 1875

Answers (1)

Abhidev
Abhidev

Reputation: 7273

You can do it without the plugin. I don't know if that plugin is doing something extra. You will have to write a custom js function to print only the div and not the entire page...

html

<div id="printDiv">
       //content Here
 </div>

js

function customPrint(id) {
     var cont = $('#'+id).html(),
         pageCont = $('body').children();// Updated

     /*Replace the page content with the div content that needs to be printed*/
     $('body').html(cont);

     /*Print function call*/
     window.print();

     /*Place the original page content back*/
     $('body').html(pageCont);
}

customPrint("printDiv");

Update

function customPrint(id) {
         var cont = $('#'+id),
             pageCont = $('body');

         /*Hide the page content*/
         pageCont.hide();
         cont.show();

         /*Print function call*/
         window.print();

         /*Display back the page content*/
         pageCont.show();
    }

Upvotes: 4

Related Questions