javascript:window.print() 打印 2 页,而我有 1 页 [英] javascript:window.print() prints 2 pages while I have 1
问题描述
我有一个简单的 HTML 文档,其中仅包含一个图像标签.我想在文档加载后打印图像.我的代码:
I have a simple HTML document which includes an image tag only. I want to print the image after document's loaded. my code:
<body>
<img id="form1" src="form1.jpg" alt="form1" style="margin: 0 auto;display:block;" onLoad="javascript:window.print()" />
</body>
它可以工作,但问题是它打印了图像(网页)和另一张空的纸张,顶部只有一个文本,它给出了图像的地址和 html 标题.如何防止打印多余的纸张?
it works but the problem is that it prints both the image ( webpage ) and another paper which is empty and only has a text on top which is giving the address of image and html title. how can I prevent from printing the extra paper ?
P.S :我使用了 jquery 插件,如 PrintElement.js、jqPrint.js 等,但它们有同样的问题......
P.S : I used jquery plugins like PrintElement.js, jqPrint.js, etc, but they have same problem...
推荐答案
您可以使用 CSS 来控制图像大小等进行打印 - 使用 @media print
You can use CSS for controlling the image size, etc for print - using @media print
给图像一个max-width
.
这样,您就可以控制图像在页面上的呈现方式.示例:
That way, you can control how the image renders on the page. Example:
@media print {
body img {
width: 90%; max-width: 1048px;
}
}
这篇关于javascript:window.print() 打印 2 页,而我有 1 页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!