Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
156
rated 0 times [  160] [ 4]  / answers: 1 / hits: 22653  / 14 Years ago, sat, september 18, 2010, 12:00:00

I have a print button with id=print_req. I wrote some Javascript code for printing a page, which is triggered by clicking on this button, and I also want to hide this button before printing, and show it after whole printing process.i mean not to print button in my printed document. Here is my code:



$(document).ready(function(){
$(#print_req).click(function(){
$(#print_req).css(display,none);
window.print();
});

$(#print_req).css(display,block);
return false;
});


This correctly hide that button, but when the printing process get done, the button won't show again! What is the problem?


More From » printing

 Answers
16

You are going at this wrong. You should not be showing and hiding the button with JavaScript or using a background image to do it. You should be using a print stylesheet that will allow you to apply different styles to the page when it is printed. In your case you would set the display to none [or visibility to hidden] in this stylesheet.



So you add a stylesheet with the media type for print



<link rel=stylesheet type=text/css media=print href=print.css />


In that print.css, you hide the button



.printButtonClass{ display : none }


And presto, the button hides when you print with no JavaScript.


[#95580] Thursday, September 16, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
sonja

Total Points: 541
Total Questions: 113
Total Answers: 114

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
sonja questions
Mon, Nov 30, 20, 00:00, 4 Years ago
Sun, Oct 11, 20, 00:00, 4 Years ago
Thu, May 21, 20, 00:00, 4 Years ago
Sun, Nov 10, 19, 00:00, 5 Years ago
Mon, Aug 26, 19, 00:00, 5 Years ago
;