Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide buttons when printing

Tags:

I have a page which contains at the bottom 3 buttons with the following coding:

    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';      }
#options {  	align-content:center;  	align-items:center;      text-align: center;  }
<div id="options">  <input type="submit" value="post news" >  <input id="printpagebutton" type="button" value="print news" onclick="printpage()"/>  <input type="button" value="re-enter the news">  </div>

I managed to hide the print button while printing but i couldn't with the others.

I've searched the internet for the solution, and most questions were answered by adding the display:none; in css, but i end up with 3 hidden buttons on the screen. I only want the buttons hidden while printing

Answer might be simple, my knowledge in web developing is acient.

Thank you in advance.

like image 910
Adnan D. Avatar asked Jul 15 '15 08:07

Adnan D.


People also ask

How do I hide print button when printing?

Use CSS @media print or a print stylesheet to hide the button when it is printed. That way it will be hidden on the printout whether the button is used to print or not.

How do I hide the elements when printing?

To hide the element, add “display:none” to the element with CSS.

How do I hide a macro button when printing?

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.

How do you make a button hidden?

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid. A hidden <button> is not visible, but maintains its position on the page.


2 Answers

You can use CSS @media queries. For instance:

@media print {    #printPageButton {      display: none;    }  }
<button id="printPageButton" onClick="window.print();">Print</button>

The styles defined within the @media print block will only be applied when printing the page. You can test it by clicking the print button in the snippet; you'll get a blank page.

like image 169
Purag Avatar answered Oct 24 '22 18:10

Purag


You can use a css media query to target print:

@media print {   .hide-print {     display: none;   } } 
like image 35
Guy Avatar answered Oct 24 '22 18:10

Guy