Avatar of sasnaktiv
sasnaktivFlag for United States of America

asked on 

Delete or hide header & footer when printing html

Hi Guys,
Is there any way to remove the header and footer of a html or php page, so that when a visitor prints it, there is no header or footer on the printed page?
Thanks,
Sas
HTMLJavaScriptPHP

Avatar of undefined
Last Comment
Rob
Avatar of Big Monty
Big Monty
Flag of United States of America image

im more of an ASP guy, but the approach would be the same...

when i want to give the user the option to print, i have them click a link or button, which brings me to another page, which is basically the same page, except there's a variable in the page that I use to determine which sections I want to print.

if you're asking about whether there's a way to do it with the generic print function within browser, then no, you will need to build your own custom print function to accomplish this
SOLUTION
Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Use CSS.  You can do it with @media print or you can have a separate style sheet like this:
<style type="text/css" media="print">...</style>

Open in new window

Avatar of sasnaktiv
sasnaktiv
Flag of United States of America image

ASKER

Thanks for the attention guys,
I've tried all of these variations with no success. It's still printing the header & footer.
So what am I doing wrong?
Below is a sample:
<html><title>No headers or footers</title><head>
<!-- ............ Attempt #1 ....................... -->
<style type="text/css" media="print">...</style>

<!-- ............ Attempt #2 ....................... -->
 <style>
@media print {
.header, .hide { visibility: hidden }
}
</style>

<!-- ............ Attempt #3 ....................... -->
<style>
@media print {
#header, #footer {display:none;}
}</style>

<!-- ............ Attempt #4 ....................... -->
     <style>
 @media print
   {
      .noprint { display: none; }
   } </style>
   
<!-- ............ Attempt #5 ....................... -->
     <style>
@media print
  {
  .yourheader, .yourfooter {display:none;}
  } </style>

</head>   
   
   <body>
   Content
   <P><input type='button' onClick="window.print()" class='hide'
value='Print'/>

</body>
</html>

Open in new window

SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of sasnaktiv
sasnaktiv
Flag of United States of America image

ASKER

Thanks Ray,
I did a copy & paste of your code, and I'm still getting the header & footer when I print it out. I'm using FF.
How can we get different results?
Sas
Avatar of sasnaktiv
sasnaktiv
Flag of United States of America image

ASKER

Hey guys, maybe I'm not clear enough.
Yes Ray when printing I do not get the words "Head" and "Foot" that appear on the html page.

So that works, but that's not what I mean by the Header & Footer.

What I mean is that once the page is printed at the very top of the page I get the "Title" and the document  "Path". At the bottom I get the "Date & Time" and "Page number".

That's the information I don't want printed out!
I hope that's clear now,
Sas
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of sasnaktiv
sasnaktiv
Flag of United States of America image

ASKER

Who says Miss Universe is unattainable?
Aim for the sky my friends.
SOLUTION
Avatar of Big Monty
Big Monty
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of sasnaktiv
sasnaktiv
Flag of United States of America image

ASKER

So there's no real solution here. Thank you all for participating.
Sas
Avatar of Rob
Rob
Flag of Australia image

That's right, in this case there the solution is there isn't one.  It's controlled by the client that your webpage just doesn't and never will have access to, hence the suggestion to use another medium such as PDF to deliver your content to guarantee that it will look the same when printed :)
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo