0

I`ve researched a lot and spent more than 24 hours on it, but what ever reason adding the following in Content Editor WebPart on SharePoint 2013 List page, doesn't does the job as expected. Expectation: To Print the content and no blank pages.

If I just give the print command with no Javascript or CSS code to customized printing, then its prints blank pages apart from the original content.

Following code added to Content Editor WebPart -

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js"> </script><script type="text/javascript">

    function PrintElem(elem)
    {
        Popup($(elem).html());
    }

    function Popup(data) 
    {
        var mywindow = window.open('', 'my div', 'height=auto,width=600');
        mywindow.document.write('<html><head><title>my div</title>');
        /*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
        mywindow.document.write('</head><body >');
        mywindow.document.write(data);
        mywindow.document.write('</body></html>');

        mywindow.print();
        mywindow.close();

        return true;
    }

</script>

<input type="button" value="Print Div" onclick="PrintElem(&#39;#WebPartWPQ2&#39;)"/>​​​​​​​​​

Please suggest where am i wrong? Also, I`ve tried with having the print.css with @media print function, but that print with extra blank pages, due to which I went for printing only the DIV content ( in order to avoid blank page)

1 Answer 1

0

without jquery:

<script type="text/javascript">

    function PrintElem(elem)
    {
      Popup(document.getElementById(elem).outerHTML); // or innerHTML
    }

    function Popup(data) 
    {
    var mywindow = window.open('', 'my div', 'height=auto,width=600');
    mywindow.document.write('<html><head><title>my div</title>');
    mywindow.document.write('</head><body >');
    mywindow.document.write(data);
    mywindow.document.write('</body></html>');

    mywindow.print();
mywindow.close();



    return true;
    }

</script>
<input type="button" value="Print Div" onclick="PrintElem('your_element_id');"/>
1
  • Tried still the same.
    – Jason
    Jul 12, 2016 at 3:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.