window.print()JavaScript的功能检测解决方案 [英] Feature detection solution for window.print() JavaScript

查看:113
本文介绍了window.print()JavaScript的功能检测解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

有什么方法可以检测对window.print()的支持吗?我宁愿去检测功能本身,也不愿意去摸索检测我是否在移动浏览器,台式机,iOS或Android或我可能在哪个特定的移动浏览器上.

背景

以下链接使我相信:

  • Apple要求所有第三方浏览器都使用UIWebView
  • 在非Safari应用程序中使用的UIWebView在运行window.print()时不起作用
  • 运行window.print()时,iOS上的Safari会做一些适当的事情

链接:

P.S.我查看了Modernizr文档,看它是否可以检测到对打印的支持,但没有发现任何东西.

P.P.S.我看到,尽管适用于GCP,但iOS版Chrome确实支持打印.在这里,只寻找特征检测而不是打印解决方案.( https://support.google.com/chrome/answer/3049815?hl = zh-CN& ref_topic = 1719889 )

修改为了澄清,似乎window.print不是任何标准的一部分:

我对这种方法的工作方式的思考越多,我对使用简单的JavaScript方法检测该功能的希望就越小,这太糟糕了.

此问题确实是https://productforums.google.com/forum/#!topic/chrome/7wTj1dteSeI

  • Javascript printing on mobile devices(ios)
  • https://stackoverflow.com/a/4362472/749227
  • http://daringfireball.net/linked/2012/06/28/chrome-ios
  • https://stackoverflow.com/a/4362472/749227
  • P.S. I looked in the Modernizr docs to see if it can detect support for printing, but didn't spot anything.

    P.P.S. I see that Chrome for iOS does support printing, albeit through GCP. Here, just looking for feature detection rather than a print solution. (https://support.google.com/chrome/answer/3049815?hl=en&ref_topic=1719889)

    Edit To clarify, it appears that window.print is not part of any standard: https://developer.mozilla.org/en-US/docs/Web/API/Window.print. If window.print exists in some browsers but doesn't do anything useful (e.g., isn't wired up to any browser-specific implementation of appropriate printing functionality) that is ultimately what I want to detect.

    My guess is that mobile browser vendors will have something defined for window.print so that any scripts that try to call it won't error; but the call may be a No op, or may send a request the the operating system that the OS simply ignores.

    The more I think about how the guts of this could be working the less hopeful I am of a simple JavaScript approach to detecting the feature, which is too bad.

    解决方案

    This question is indeed a duplicate of Determine whether browser supports printing. See carpetsmoker's comment on this question and the answer referred to. I agree, that may be the best we can do for now.

    Even if window.print isn't part of any standard, it'd be nice if browser vendors implemented and agreed upon some API for detection. Perhaps they're all internally working on an appropriate implementation for the function and so don't want to throw out there something temporary that'll be useless later. Oh, well.

    这篇关于window.print()JavaScript的功能检测解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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