Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
1  
Can you tell us a bit more about what exactly you are trying to do? –  Yannis Rizos Aug 17 '12 at 15:50
    
I added some additional detail –  LFHprint Aug 17 '12 at 15:53
add comment

2 Answers

up vote 4 down vote accepted

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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