javascript 如何通过javascript在没有url和datetime的情况下打印
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5360158/
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
how to print without url and datetime by javascript
提问by pooja
I want to print the div tag content by javascript by using the following code.
我想使用以下代码通过 javascript 打印 div 标签内容。
var divToPrint1 = $('#PrintDoc').html();
var newWin = window.open('Share Certificate #001', '', 'width=10px,height=10px');
newWin.document.open();
newWin.document.write('<html><body onload="window.print();">' + divToPrint1 + '</body></html>');
newWin.document.close();
setTimeout(function () { newWin.close(); }, 10);
And print code works fine. But now I want to remove the url, date and title from the printed page by using the javascript code.
打印代码工作正常。但现在我想使用 javascript 代码从打印页面中删除 url、日期和标题。
Is it possible? Can you help me to solve the following code?
是否可以?你能帮我解决下面的代码吗?
回答by Michael Jasper
The only online application I have seen that prints without the header and footer is Google Docs. However, after some searching I discovered that gdocs actually generates a pdf file, opens that file, and the prints from there. If that's the best way that Google has found to do it, with all their resources, I would suggest looking that direction.
我见过的唯一打印没有页眉和页脚的在线应用程序是 Google Docs。但是,经过一番搜索后,我发现 gdocs 实际上生成了一个 pdf 文件,打开该文件,然后从那里打印出来。如果这是谷歌找到的最好的方法,加上他们所有的资源,我建议朝那个方向看。
"The headers and footers are put there by your printing subsystem, not by the page or the browser. What that means is, this particular attribute is in the hands of the user. Much like screen resolution or brower width." - an answer from a webdesign forum
“页眉和页脚由您的打印子系统放置在那里,而不是由页面或浏览器放置。这意味着,这个特定属性掌握在用户手中。很像屏幕分辨率或浏览器宽度。” - 来自网页设计论坛的回答
Thisis a service (paid though) that I found that will generate a pdf via http post. And hereis a (seems promising) s.o. question about generating pdfs using asp.net
这是我发现的一项服务(尽管付费),它将通过 http 帖子生成 pdf。而这里是关于使用PDF文件生成一个asp.net(很有前途),所以问题
回答by PleaseStand
There exists no way to remove the browser's header and footer from printed pages from JavaScript. Either the user will have to turn those off manually or you will have to render the content as a PDF file on the server, as Adobe Reader does not add a header or footer.
没有办法从 JavaScript 的打印页面中删除浏览器的页眉和页脚。要么用户必须手动关闭它们,要么您必须在服务器上将内容呈现为 PDF 文件,因为 Adobe Reader 不添加页眉或页脚。
回答by Mahesh Kumar
<style type="text/css" media="print">
@page
{
size: auto;
margin: 0mm;
}
body
{
background-color:#FFFFFF;
border: solid 1px black ;
margin: 0px;
}
</style>
回答by Jah Yusuff
there is solution in the browser side itself. mentioned the Steps to disable the Header and footer in all the three browsers.
浏览器端本身有解决方案。提到了在所有三个浏览器中禁用页眉和页脚的步骤。
Chrome Click the Menu icon in the top right corner of the browser. Click Print. Uncheck Headers and Footers under the Options section.
Chrome 单击浏览器右上角的菜单图标。单击打印。取消选中选项部分下的页眉和页脚。
Firefox Click Firefox in the top left corner of the browser. Place your mouse over Print, the click Page Setup. Click the Margins & Header/Footer tab. Change each value under Headers & Footers to --blank--.
Firefox 单击浏览器左上角的 Firefox。将鼠标放在“打印”上,单击“页面设置”。单击边距和页眉/页脚选项卡。将页眉和页脚下的每个值更改为 --blank--。
Internet Explorer Click the Gear icon in the top right corner of the browser. Place your mouse over Print, then click Page Setup. Change each value under Headers and Footers to -Empty-.
Internet Explorer 单击浏览器右上角的齿轮图标。将鼠标放在“打印”上,然后单击“页面设置”。将页眉和页脚下的每个值更改为 -Empty-。
回答by yves.beutler
Try the following css code snippet
试试下面的 css 代码片段
<style type="text\css" media="print">
#myFooter, #myHeader
{
display: none;
}
</style>