0

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.

2
  • Hide the first one before you print. Commented Nov 14, 2014 at 18:08
  • Two pages inside a web page? Could you explain a little more? Commented Nov 14, 2014 at 18:22

1 Answer 1

1

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";
Sign up to request clarification or add additional context in comments.

4 Comments

I didn't want to hide the div.
@Axeem: It only hides it for printing, not on screen. That's the whole point of a print style sheet (note the @media print wrapper).
In chrome window.print() function open chrome print dialog. I want to open window print dialog any suggestion. thanks
@Axeem: That's a completely unrelated question, but: You have no control over that. All you can do is ask the browser to print. How it does that is up to the browser vendor and any user preferences they provide (for instance, Chrome offers a "Open system print dialog" option at the bottom of its print dialog).

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.