tags:

views:

3533

answers:

5

My Problem is when i click print option On my webpage it is print the webpage but "The Print Link Lable Also Visible On webpage".

So Please Give The Javascript Or HTML code To Hide The LInk Button When I Click The Print link

Example:
"Good Evening"

                       Print (click Here To Print)

I Want To Hide This "Print" Leble When it print The Text "Good Evening".After Printing Page this "Print" lable Will Not show on print Paper.

+1  A: 

You could place the link within a div, then use JavaScript on the A tag to hide the div when clicked. Example (not tested, may need to be tweaked but you get the idea):

<div id="printOption">
<a href="javascript:void();" onclick="document.getElementById('printOption').style.visibility = 'hidden'; document.print(); return true;">Print</a>
</div>

The downside is that once clicked, the button disappears and they lose that option on the page (there's always Ctrl+P though).

The better solution would be to create a print stylesheet and within that stylesheet specify the hidden status of the printOption ID (or whatever you call it). You can do this in the head section of the HTML and specify a second stylesheet with a media attribute.

Justin Scott
+23  A: 

The best practice is to use a style sheet specifically for printing, and and set it's media attribute to print.

In it, show / hide the elements that you want to be printed on paper.

<link rel="stylesheet" type="text/css" href="print.css" media="print" />
Andreas Grech
In here you should also have css to not display other wrapper content, change the font-family to a better value, remove widths to allow for complete use of the page. If you set your main stylesheet to media="screen" you can treat your print stylesheet as a new playgound.
Steve Perks
I completely aggree. This is the way to do it.
Pete
Absolutely. And with this approach, you can either just remove "Click here for printable version" or add "This page is printer-friendly" or similar. Good practice is, as Steve Perks said, remove all unnessecary content like navigation, ads and the like. Include only the primary content of the page.
Arve Systad
+17  A: 

In your stylesheet add:

@media print {
.noPrint {
    display:none;
}
}

Then add class='noprint' (or add the noprint class to an exsiting class statement) in your HTML that you don't want to appear in the printed version, such as your button.

Diodeus
A: 

The best thing to do is to create a "print-only" version of the page.

Oh, wait... this isn't 1999 anymore. Use a print CSS with "display: none".

there is still some value in printable versions because it clearly displays to the user what they'll get when they print which can be abused with CSS techniques
annakata
added to that, you can include additional content on a print version like link references, footers, etc. In days to come, a lot of this will be achievable through css too though.
Steve Perks
A: 

work perfect ...

but dont use document.print(); use only print();