Javascript window.print() 没有打印整个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10845621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:12:52  来源:igfitidea点击:

window.print() is not printing the whole page

javascriptjquery

提问by Basit

I have a page screenShot

我有一个页面 截屏

I want to print this page. On print button i am using something like this

我想打印此页。在打印按钮上,我正在使用这样的东西

<input id="print" type="submit" onclick="window.print();" />

But the problem is it is not printing the whole page. Like it only print that is currently in the view. When i click on the print button then till Email:[email protected]page print. It does not print the text below the scrollbar.

但问题是它没有打印整个页面。喜欢它只打印当前在视图中。当我点击打印按钮然后直到Email:[email protected]页面打印。它不会打印滚动条下方的文本。

textBelowScrollbar

滚动条下方的文字

How can i print the whole text. Like suppose i have a very big page and i am using tabs to accommodate my page. And when click on print button, then i want to include the whole page including tabs. How can i do it?

我怎样才能打印整个文本。就像假设我有一个非常大的页面,并且我正在使用标签来容纳我的页面。当点击打印按钮时,我想包括整个页面,包括标签。我该怎么做?

Thanks

谢谢

采纳答案by undefined

you should use a separate css file for printing the page or use css3 media queries:

您应该使用单独的 css 文件来打印页面或使用 css3 媒体查询:

<link rel="stylesheet" href="css/print.css" type="text/css" media="print"/>

using percentage values its the best option when you create a css print file.

创建 css 打印文件时,使用百分比值是最佳选择。

body, html, #wrapper {
    width: 100%;
}

or in your main css file:

或在您的主 css 文件中:

@media print {
      body, html, #wrapper {
          width: 100%;
      }
}

回答by Kariuki James

use

  body,html { margin-top:0%;
   display:block;
   height:100%;}

回答by Roberto

Try using CSS print stylesheets, have a look at google for some examples.

尝试使用 CSS 打印样式表,看看谷歌的一些例子

On why it actually doesn't print the whole page, I assume you're missing a setting on your print dialog that states how the printing will be done.

关于为什么它实际上不打印整个页面,我假设您在打印对话框中缺少一个说明打印将如何完成的设置。