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

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

问题描述

我认为这个问题的答案几乎肯定是不,因为我已经做了一些测试和周围搜索,但没有任何诀窍,以检测是否 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.

我的Andr​​oid手机有一个 window.print()的功能,但它(不出所料)不会做任何事情。

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

再次声明,我问大多所以有在等话题一个很好的问题: - )

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

推荐答案

不幸的是,它看起来像一个没有。所述window.print()函数不是EMCAScript规范的一部分。这意味着'; S不需要为它是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.

来源:

  • https://developer.mozilla.org/en/DOM/window.print
  • http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf

编辑:

可爱的小剧本我写测试我的浏览器,只检查打印功能的存在,然后询问打印:

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天全站免登陆