判断浏览器是否支持打印 [英] Determine whether browser supports printing

查看:34
本文介绍了判断浏览器是否支持打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为这个答案几乎肯定是否",因为我已经做了一些测试和搜索,但是有没有什么技巧可以检测 window.print() 甚至 可能在页面内部工作(即,从 JavaScript)?我知道,即使在台式机/笔记本电脑上,也永远不可能知道系统上是否配置了打印机,但至少浏览器会显示打印对话框.

I think the answer to this is almost certainly "no", because I've done a little testing and searching around, but is there any trick to detect whether window.print() even might work from inside a page (i.e., from JavaScript)? I know that even on a desktop/laptop it's never going to be possible to know whether there's a printer configured on the system, for example, but at least the browser will put up a print dialog.

我的 Android 手机有一个 window.print() 函数,但它(不出所料)没有任何作用.

My Android phone has a window.print() function but it (unsurprisingly) doesn't do anything.

再说一次,我主要是问,所以在 SO 上有一个关于这个主题的好问题 :-)

Again I'm asking mostly so there's a good question on the topic at SO :-)

推荐答案

不幸的是,它看起来像一个不.window.print() 函数不是 EMCAScript 规范的一部分.这意味着它不需要成为 JavaScript 语言的一部分,也没有适当的文档来说明它的实现.这是未定义的行为,因此对其进行测试看起来非常困难.

Unfortunately it looks like a no. The window.print() function is not part of the EMCAScript specification. This means that there's no requirement for it to be part of the JavaScript language, and no proper documentation for its implementation. It's undefined behaviour and so testing for it looks very difficult.

来源:

我写的可爱的小脚本来测试我的浏览器,只是检查打印功能是否存在,然后要求打印:

Cute little script I wrote to test my browsers, just checks the print function exists and then asks to print:

if(window.print) {
    if(confirm('I can print. Would you like to?'))
        window.print()
}

这篇关于判断浏览器是否支持打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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