How to Print it? Only Text | SoloLearn: Learn to code for FREE!

+10

How to Print it? Only Text

I Want Print Only Text or Customized Page, Like a Only Text and Hide Print Button. https://code.sololearn.com/Wx701J6OdVIi/?ref=app

3/4/2021 10:02:58 PM

AYESHA NOOR

5 Answers

New Answer

+8

It sounds like you want the print preview and hard copies to show the "Print Only Text" but not have it show in the regular page. You'd want to use CSS's media selector for print and screen. Add this to your CSS tab: h1 { display: none; } @media print { h1 { display: block; /* show the "Print Only Text" in print media. */ } input[type="button"] { display: none; /* hide the Print button in print media. */ } }

+5

Ayesha wrote, "Why you hide <h1> tage ?" Response: I used CSS to hide it because it said "ONLY PRINT THIS TEXT". I interpretted that as make that text exclusive to printing and hidden to all other media. If you wanted it shown whether the page is being printed or not, just remove all my references to h1. In other words, this would be the only CSS you should use: @media print { input[type="button"] { display: none; /* hide the Print button in print media. */ } }

+5

Get button in js and simply remove it from page then print page

+5

<!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <h1>ONLY PRINT THIS TEXT</h1> <form> <input type=button name=print value="Click" onClick="this.remove();javascript:window.print()"></form> </body> </html>

+3

Why you hide <h1> tage ?