最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to pass printing range of pages in javascript using window.print()? - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Oct 25, 2012 at 6:11 lukad 17.9k3 gold badges38 silver badges56 bronze badges asked Oct 25, 2012 at 6:07 Shanky_RicherShanky_Richer 2231 gold badge3 silver badges8 bronze badges
Add a ment  | 

5 Answers 5

Reset to default 3

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.

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.

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.

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.

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;
  }  
}
发布评论

评论列表(0)

  1. 暂无评论