开发者

how to print without url and datetime by javascript

开发者 https://www.devze.com 2023-02-18 00:05 出处:网络
I want to print the div tag content by javascript by using the following code. var divToPrint1 = $(\'#PrintDoc\').html();

I want to print the div tag content by javascript by using the following code.

var divToPrint1 = $('#PrintDoc').html();
 var newWin = window.open('Share Certificate #001', '', 'width=10px,heigh开发者_如何学运维t=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.

Is it possible? Can you help me to solve the following code?


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.

"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

This is a service (paid though) that I found that will generate a pdf via http post. And here is a (seems promising) s.o. question about generating pdfs using asp.net


<style type="text/css" media="print">   
@page   
{  
size: auto;   
margin: 0mm;  
}  
body  
{  
background-color:#FFFFFF;   
border: solid 1px black ;  
margin: 0px;  
}                
</style>


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.


Try the following css code snippet

<style type="text\css" media="print">
  #myFooter, #myHeader
  {
    display: none;
  }
</style>


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.

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--.

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-.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号