A client has asked for a print button be added to their site and would like it to be hidden for users who don't have the capability to print, e.g. most mobile devices.
Is there any way through JavaScript to detect if a client has printing capabilities?
The requirement is flawed since most user agents can "print" and the knowledge of whether or not a UA can print is not the websites busines.
Many mobile browsers can print and most web browsers can print even if there is no printer attached (print to pdf, cloud print etc). It is a bit of a security problem for any user agent to explicitly state anything about its printing capabilities without the user's knowledge. That is what the printing stylesheet is there for (so the website doesn't have to know if it is being printed at all).
What you can do is hide the button on user agents with small screens, those users can still print their documents using the user agent itself. You could also detect specific user agents and hide the button for them.
Links
http://www.alistapart.com/articles/return-of-the-mobile-stylesheet : discusses mobile stylesheets and related issues.
http://mobile.smashingmagazine.com/2010/11/03/how-to-build-a-mobile-website/#mobile-stylesheets : more about mobile stylesheets.
Basic mobile stylesheet attachment:
<link rel="stylesheet" href="mobile.css" media="handheld" />
Detecting by screen size:
<link rel="stylesheet" href="mobile.css"
media="only screen and (max-device width:480px)"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With