I am working on a HTML and javascript project. I want to print my document using javascript.
I am using window.print()
to print. But how can i pass printing range also? eg: If a document contains 20 pages and i want to print pages from 5-10 only.

- 17,287
- 3
- 36
- 53

- 193
- 1
- 2
- 7
5 Answers
You cannot set a range using window.print()
, using window.print()
invokes your print preferences window which is native print window, where you can set the page range manually..
Perhaps you can dynamically set a class for the content you don't want to get printed, using print specific stylesheet or media queries.

- 153,751
- 34
- 298
- 278
-
Alien: Hi I am trying to print range in window.print(). Can you give me some example on how to print range using javascript – user575219 Oct 18 '15 at 03:39
-
@user575219 My answer says you cannot set a range :) – Mr. Alien Oct 18 '15 at 04:13
-
How does it work on my machine sometimes and not the clients machine.? Do you think you could look at my question. I am buliding like a HTML Element with all pages combined. http://stackoverflow.com/questions/33161283/silverlight-html-bridge-printing-window-print-blank-pages – user575219 Oct 19 '15 at 01:46
window.print()
does not accept any arguments,
but you could make use of the: window.onbeforeprint
event for your case.
Just toggle display: none
for the sections in your page you do not wish to be printed.

- 10,049
- 9
- 41
- 64
You can't do that. All window.print()
can do is open the operating system's default print dialog.
But maybe you could do something like hiding those parts of site that shouln't be printed.

- 17,287
- 3
- 36
- 53
You have the option of installing an ActiveX control (perhaps if this is for an internal application) that would expose those values to you through javascript. I've used MeadCo ScriptX for this in the past and it's worked out quite nicely.

- 762
- 10
- 27
I use print
@media rule to check if it is print or not and then hide certain elements based on that:
@media print {
.hide-print {
display: none !important;
}
}

- 896
- 9
- 13