How to remove header / footer with code

I am using the following code to print a page in my application ...

<html><body onload=""window.print();"">" sHtmlBody = sHtmlBody & "<body>" 

window.print() working fine. I know, as soon as printing appears, I can manually go to settings and delete headers and footers. In IE, I know that I need to go to print preview, and then delete print headers. A.

However, is there any line of code that does this automatically, so users of the application do not need to do this?

EDIT:

  sHtmlBody = "<style type='text/css'>" sHtmlBody = sHtmlBody & " @media print{" sHtmlBody = sHtmlBody & " body{ background-color:#FFFFFF; background-image:none; color:#000000 }" sHtmlBody = sHtmlBody & " #ad{ display:none;}" sHtmlBody = sHtmlBody & " #leftbar{ display:none;}" sHtmlBody = sHtmlBody & " #contentarea{ width:100%;}" sHtmlBody = sHtmlBody & " }" sHtmlBody = sHtmlBody & " </style>" sHtmlBody = sHtmlBody & "<html><body onload=""window.print();"">" sHtmlBody = sHtmlBody & "<body>" 
+4
source share
1 answer

you can do this with CSS, before printing, set the CSS page. eg:

 <style type="text/css"> @media print{ body{ background-color:#FFFFFF; background-image:none; color:#000000 } #ad{ display:none;} #leftbar{ display:none;} #contentarea{ width:100%;} } </style> 

This code, added to the page, hides 2 divs with the identifiers "ad" and "leftbar", plus makes additional changes to the rest of the document when printing. A.

IF you ask about specific browser settings, such as the date and time of printing, then I think this is not possible with code. Check this out: Remove the default browser header and footer when printing HTML

+7
source

All Articles