2

I have a line of text I would like to display only when a webpage is being printed. Is it possible to only display this line when printing the page or doing a print preview using PHP in some way?

Basically, I want to print a page without the print headers, but would like to include the page's URL within the page's content when it is printed.

  • 1
    Can you tell us a bit more about what exactly you are trying to do? – yannis Aug 17 '12 at 15:50
  • I added some additional detail – LFHprint Aug 17 '12 at 15:53
4

You can create a CSS stylesheet that only applies to Print media.

For example:

                                             Notice the media----v
<link rel="stylesheet" href="print.css" type="text/css" media="print" />

In your regular CSS stylesheet, just hide that element:

p.print-notice {
    visibility: hidden;
}

And in your print CSS stylesheet, bring it up again:

p.print-notice {
    visibility: visible;
}

Note: Setting visibility to hidden, only hides the element but does not remove it from the document flow. Use the Display property if you want to remove it from flow.

1

You might have more luck doing this with CSS and just showing or hiding the element(s) when printing using "@media print". A little more information is here: http://webdesign.about.com/cs/css/qt/tipcssatmedia.htm but you can probably find more by doing some searches for CSS media types.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.