Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  83] [ 6]  / answers: 1 / hits: 45616  / 13 Years ago, mon, october 10, 2011, 12:00:00

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>

More From » printing

 Answers
6

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


[#89706] Friday, October 7, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
payne

Total Points: 527
Total Questions: 108
Total Answers: 88

Location: Tajikistan
Member since Thu, Apr 14, 2022
2 Years ago
payne questions
Thu, Sep 3, 20, 00:00, 4 Years ago
Tue, Aug 18, 20, 00:00, 4 Years ago
Thu, Oct 11, 18, 00:00, 6 Years ago
;