Determine whether browser supports printing

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.

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 :-)

-------------Problems Reply------------

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.

Sources:

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

EDIT:

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()
}

The print() method is synchronous. This makes it possible to do the aftermath in order to decide wether a print dialog has been shown

var start = +new Date();
window.print();
var delta = + new Date() - start;
console.log(delta);
if (delta > 100) { console.log('It worked'); }

The beforeprint and afterprint events may help, but I'm not sure about browser support.

Edit: Webkit does not support them

Category:javascript Views:0 Time:2012-02-13

Related post

  • Determine whether browser supports javascript from within iFrame? 2009-01-28

    I am building an iframe that will go into my clients' web pages. I need to figure out if the user's browser supports javascript and serve back the either the javascript or non-javascript version of the page accordingly. What's the best way to determi

  • Determine if browser supports windows integrated authentication 2009-06-22

    Is there a way to determine if a browser supports NTLM without having NTLM enabled for the particular site or directory in IIS and without showing a login dialog/pop-up? Preferably, determine this using ColdFusion or perhaps some combination of JS an

  • how to determine if the browser supports selectionStart if there is no text selected 2010-06-23

    This code will return true if the browser supports selectionStart and some text is selected, but if no text is selected it returns false (even on browsers that support it): if (el.selectionStart) { } How do you determine if the property is available

  • Is there a way to use javascript to determine if the current browser supports hiding tags? 2010-10-01

    Updated question: Is there a way to use javascript to feature sniff, rather than the evil, browser sniff, to determine if the current browser supports/doesn't support hiding tags? IE does not support hiding tags in the select element. So I'd like to

  • Is there any way to quickly determine if a browser supports CORS-enabled images not tainting the browser? 2011-12-08

    Is there a quick test to determine if a browser supports CORS-enabled images not tainting a canvas when drawn on them. I know Chrome 15 supports this, Firefox 9Beta but not Firefox 8, Safari doesn't, IE9 doesn't. But there must be a pretty simple tes

  • Detect Browser Support for display:inline-block 2009-03-02

    How can you detect if a browser supports the CSS attribute display:inline-block? --------------Solutions------------- There is no way to detect that with Javascript as it is a pure CSS attribute that does not relate to any object or function in Javas

  • What's browser support like for bare SWF files? 2009-08-31

    Does anybody use bare .SWF files as webpages? I know it's possible; it seems to work fine for me. Why would I embed a SWF inside an HTML page if it's just going to be full screen (I mean the size of the browser's normal viewable page area, not COMPLE

  • WPF in a browser and printing 2009-10-16

    Can WPF be hosted in a web browser? If so how? (I think it can as I have seen some examples of it.) While hosted in the web browser what printing support does it have? What are the drawbacks to using WPF in a browser? My company is looking for a rich

  • Detecting SSL Browser support 2010-07-19

    How can you detect if the client browser has SSL support? I am not refering to the server Variables HTTPS_* . I want to be able to determine if the browser has no SSL support. P.S. I know this is possible because this company (http://www.cyscape.com)

  • How can I check if my browser supports HSL colours in Javascript? 2010-12-29

    I want to be able to determine if a browser supports HSL colours, if not then I want to fall back on generated RGB colours (i have both generated). Is there any way to do that without actually checking what browser the user is using? --------------So

  • How to force window.open() to open new tabs, whenever the browser supports them? 2011-01-31

    I have developed a Web site one of whose requirements was that every link open in a new window or tab. For obvious reasons, it is preferable that several tabs, instead of several windows be created. How do I make JavaScript's window.open() function a

  • How to use feature detection to know if browser supports css hover? 2011-02-09

    How can I use feature detection to determine whether a browser supports the :hover pseudo class? I want to do this WITHOUT using conditional comments to include ie6-specific script files if possible. --------------Solutions------------- The :hover ps

  • check if browser supports data uri at run time 2011-06-05

    I am looking to use data uri base 64 strings in my asp.net c# web application. I know only some browsers support this, so at runtime I will need to check if the current browser supports base 64 strings. From the users request object, I can access the

  • Programmatic way to see if client browser supports PUT / DELETE methods 2011-07-08

    Is there a way to see if a client browser supports PUT or SEARCH methods for usage with JQuery & AJAX requests? HTML5 PUT/DELETE methods not working in Chrome? Are the PUT, DELETE, HEAD, etc methods available in most web browsers? I have the foll

  • Deciding on a font: browser support for Cambria and other fonts? 2011-08-02

    Our web designer suggested using Cambria as a font. In looking at various font references online, we couldn't find authoritative sources that listed recent (post 2010) browser support for various fonts. Which sources do you use to determine how suppo

  • Testing if a browser supports multiple file uploads? 2011-10-21

    Is there a way to test if a given browser supports the multiple attribute on file upload elements? Either a server-side or client-side implementation is sufficient. I do realize I can test the user-agent against a list of known browsers that support

  • How do i check whether the browser supports HTML5 using c#.net 2011-11-10

    Possible Duplicate: ASP.NET - How to check browser support html5? Is there any possible solution in .NET to check whether the browser is supporting the HTML 5? Thanks --------------Solutions------------- Have a look at Dive Into HTML5 , it is client

  • How can I force the browser to print a PDF version of a webpage? 2012-03-12

    Consider a static HTML page as test.html, and a printable version of the page has been stored in test.pdf. How can I guide browser to load and print test.pdf instead of test.html when visitors tell their browser to print? If it's not possible how can

  • How can I detect if a browser supports the blink tag? 2012-04-20

    The HTML <blink> tag, in browsers that support it (i.e. Mozilla Firefox and Opera), makes its content blink on and off, resembling the effect of a slow strobe light. I am writing a suite of polyfills for non-standard HTML, including the blink t

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.138 (s). 11 q(s)