1

I have a Print button on one of my pages and I would like to control when this button gets displayed because it doesn't make sense to print using your mobile phone or tablets (I think - correct me if I'm wrong).

I saw this SO question and I noticed there are overlaps in terms of the view-port widths. Which means I could potentially hide that button for low-res laptops and desktops even though they are capable of printing the page.

@media (min-width:320px)  { /* smartphones, iPhone, portrait 480x320 phones */ }
@media (min-width:481px)  { /* portrait e-readers (Nook/Kindle), smaller tablets @ 600 or @ 640 wide. */ }
@media (min-width:641px)  { /* portrait tablets, portrait iPad, landscape e-readers, landscape 800x480 or 854x480 phones */ }
@media (min-width:961px)  { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }

Is there a way for me to know that the user agent has the ability to print the page either via CSS or jQuery so I can control when to display the Print button?

Community
  • 1
  • 1
dokgu
  • 4,957
  • 3
  • 39
  • 77
  • 2
    I know it isn't the answer to your question, but just wanted to point out that printing is still *very* relevant from devices other than a computer. Most printers these days connect via WiFi and so it's nice to be able to print from any device. – Tyler Roper Oct 13 '16 at 15:08
  • 2
    I expect you probably can print from most Windows tablets, and possibly lots of others. – DBS Oct 13 '16 at 15:08
  • 1
    Why do you think that printing from the phone is impossible? – Qwertiy Oct 13 '16 at 15:12
  • @Santi and @DBS Ok - I tried to click on the button in my Android phone and instead of asking me to print it asked me to save it as a PDF. Is there a way for me to know so I can change the label of the button to something like a `Save as a PDF`? – dokgu Oct 13 '16 at 15:13
  • 1
    @Qwertiy I just never done it. Like I said - correct me if I'm wrong. – dokgu Oct 13 '16 at 15:13
  • 2
    @PatrickGregorio CSS has a `handheld` media query but it is widely ignored by modern devices, and resolution cannot be trusted as new devices have higher resolution than some computers. You may have to look into a javascript/jquery solution. Maybe try something like [this](http://stackoverflow.com/a/25543217/2026606) - a slight bit dated but it's Vanilla JS so it should be alright. – Tyler Roper Oct 13 '16 at 15:22
  • 2
    Thanks everyone. My boss says to leave the button there. – dokgu Oct 13 '16 at 15:32
  • 2
    Despite whether hiding this button is a bad idea or not, this is an interesting question worth answering: "Is there a way for me to know that the user agent has the ability to print the page either via CSS or jQuery so I can control when to display the Print button?" Or are there even any devices that absolutely can not print? – Eric N Oct 13 '16 at 16:13

0 Answers0