2

I have a javascript print function:

    function printDetails() {
        var printContent = document.getElementById('<%= divMail.ClientID %>');

        var windowUrl = 'about:blank';
        var uniqueName = new Date();
        var windowName = 'Print' + uniqueName.getTime();
        var printWindow = window.open(windowUrl, windowName, 'left=500,top=500,width=0,height=0');
        printWindow.document.write(printContent.innerHTML);

        printWindow.document.close();
        printWindow.focus();
        printWindow.print();

        printWindow.close();

        return false;
    }

I have the following HTML:

<div id="divMail" runat="server" >
    <div id="showTopDetailsContent" style="display: none; position:relative;">
        MORE HTML
    </div>
</div>

And the following JQuery/Script:

$('#showTopDetailsContent').toggle(300);

The problem: When I Print I get the Contents of the divMail (DIV) and send them to the Print Function, the problem is that since I have a DIV inside divMail that is Hidden it will not be displayed in the Print. How do I make the Print Function Display that hidden DIV?

3 Answers 3

4

try this:

printWindow.document.getElementById('showTopDetailsContent').style.display='block';

after the

printWindow.document.write(printContent.innerHTML);
Sign up to request clarification or add additional context in comments.

Comments

2

You can specify it as visible for printing in CSS:

@media screen {
    #showTopDetailsContent { display: none; }
    #showTopDetailsContent.show { display: block; }
}
@media print {
    #showTopDetailsContent { display: block !important; }
}

And instead of using .toggle() which applies inline styles, use a class.

$('#showTopDetailsContent').toggleClass('show');

2 Comments

I don't know someone else thumbed down your comment, anyway, it did not work because the print function opens a new window and the @media print is not available there.
@EricBergman - If the CSS block is inside the DIV divMail it will be available in the printWindow as well.
0

you need to suppress the border in CSS

/* stop page from printing footer */
@page {
    size: auto;   /* auto is the initial value */
    margin: 0mm;  /* this affects the margin in the printer settings */
}

but that will put your content close to the edge so I'd wrap everything in a DIV with some padding

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.