Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

The window.print() is working fine. I know once the print comes up I can manually go into the settings and remove headers and footer. On IE I know that I have to go to print preview and then remove the print headers.

However, is there some line of code which does this automatically so the users of the application don't have 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>"
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
646 views
Welcome To Ask or Share your Answers For Others

1 Answer

you can do with the help of CSS , before print set the CSS of the page . for example:

<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 when added to the page hides the 2 divs with ids "ad" and "leftbar", plus makes additional changes to the rest of the document when it's printed.

IF you are asking about browser specific settings like print date and time , then i think it is not possible through code. check this out : Remove the default browser header and footer when printing HTML


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...