Axeem
Axeem

Reputation: 191

Print a selected page using javascript/jquery

I have two pages in a webpage and I want to print out the second page only.

page1
........
content
........
.......
end page 1

page 2
.......
content
......
.......
end page 2

I am using window.print() function it print both two pages but I want to print only second page page 2.
One solution is here that I always select second page on window print dialog box. But I want to do it automatically.
Thanks.

Upvotes: 0

Views: 452

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1073978

Put the content of the first page in a container with a class, no-print, and use a print style sheet:

@media print {
    .no-print {
        display: none;
    }
}

If you need to let the user choose, start out without the class on either page, and then put no-print on all of the page(s) that you don't want to print.

document.getElementById("id-for-the-page-not-to-print").className += " no-print";

Upvotes: 1

Related Questions