Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I hide button before printing and show it when printind process has been completed?

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?

like image 507
armin etemadi Avatar asked Sep 18 '10 11:09

armin etemadi


People also ask

How to set the print button visibility to hide in JavaScript?

function printpage () { //Get the print button and put it into a variable var printButton = document.getElementById ("printpagebutton"); //Set the print button visibility to 'hidden' printButton.style.visibility = 'hidden'; //Print the page content window.print () printButton.style.visibility = 'visible'; }

How to hide button when printing worksheet in Excel?

To change the button property can help you to hide it when printing the worksheet, please do as this: 1. Activate the worksheet with the button that you want to print, and then click Developer > Design Mode, see screenshot:

How do I stop a button from being printed?

In design view, right-click on the button you created, select Format Control, then the Properties tab. Deselect 'Print Object.' This should stop the button from being printed. Welcome to the Mr Excel board! If the Command button is from the Forms toolbar, then right click the button and choose "Format Control..."

How do I hide an element when printing a web page?

How do I hide an element when printing a web page? To hide the element, add “display:none” to the element with CSS.


1 Answers

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.

like image 149
epascarello Avatar answered Oct 31 '22 17:10

epascarello