检测用户是否具有打印功能? [英] Detect if user has printing capabilities?

查看:110
本文介绍了检测用户是否具有打印功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户要求在他们的网站上添加一个打印按钮,并且希望它对于没有打印能力的用户来说是隐藏的,例如,大多数移动设备。

有什么方法可以通过JavaScript来检测客户端是否具有打印功能?

解决方案

由于大多数用户代理可以打印,并且UA是否可以打印的知识不是必需的网站业务。

许多移动浏览器都可以打印,即使没有连接打印机,也可以打印大多数网页浏览器(打印到pdf,云打印等)。对于任何用户代理而言,在用户不知情的情况下明确声明其打印功能的任何内容都是一个安全问题。这就是印刷样式表的用途(因此网站不必知道它是否被打印)。



你可以做的是隐藏按钮在小屏幕的用户代理上,那些用户仍然可以使用用户代理本身打印他们的文档。您可以检测特定的用户代理并隐藏它们的按钮。



链接

http://www.alistapart.com/articles/return-of-the-mobile-stylesheet :讨论移动样式表和相关问题。



http://mobile.smashingmagazine.com/2010/11/03/how-to-build-a-mobile-website/#mobile样式表:更多关于移动样式表。



基本的移动样式表附件:

< link rel =stylesheethref =mobile.cssmedia =handheld/>



屏幕大小:

< link rel =stylesheethref =mobile.css
media =only screen and(最大设备宽度:480px)/>


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)"/>

这篇关于检测用户是否具有打印功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆