19

On Android devices (I have tested Nexus 5, Nexus 10, Galaxy S4 and Galaxy Tab 3), the window.print() command in JavaScript doesn't do anything. As far as I can tell it doesn't even register an error.

I know for a fact that most if not all of these browsers can print because you can use mobile Chrome's menu to choose "print".

Why doesn't window.print() trigger the behavior you would expect (opening the clients print menu)? And is there an Android alternative to window.print()?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MarshallOfSound
  • 2,629
  • 1
  • 20
  • 26
  • You need an app to print from an android: https://play.google.com/store/apps/details?id=com.google.android.apps.cloudprint&hl=en – Ian Hazzard Nov 08 '14 at 05:42

7 Answers7

9

It is clearly stated in this Documentation, "The command is supported on iOS, Chrome on Windows and Safari and Chrome on Mac. It is not supported on Android."

Android phones don't have native support for printing yet, so window.print() will not work. Which means you need to use third-party app to do the printing. You could find some alternatives in this article.

Harry
  • 568
  • 1
  • 5
  • 20
  • yea i installed google cloud print app, when i click the google cloud print button, the dialog box will open and i choose printer then click the print nothing happen. now what should i do? – Karthi Mar 03 '17 at 10:44
7

I'm working on a simular problem and came up with this solution:

$(document).ready(function($) {
  var ua = navigator.userAgent.toLowerCase();
  var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");

  $('button.print').click(function(e) {
    e.preventDefault();
    if (isAndroid) {
      // https://developers.google.com/cloud-print/docs/gadget
      var gadget = new cloudprint.Gadget();
      gadget.setPrintDocument("url", $('title').html(), window.location.href, "utf-8");
      gadget.openPrintDialog();
    } else {
      window.print();
    }
    return false;
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<button class="print">Print this page</button>

I haven't had the time to check if this works, i don't have an android device with me at the moment. I Would love to have some feedback on this ;-)

Jonathan Joosten
  • 1,499
  • 12
  • 12
  • This is a nice solution, actually more or less what I went with in the end, but my main concern was that I can do the equivilent of File -> Print on my android device (Menu button -> Print) but I can not trigger this with the semi standard `window.print()` function – MarshallOfSound Mar 06 '15 at 11:41
  • I could not find the Print command on Chrome android. I can find share ... > Printer. – Dave Feb 28 '17 at 17:28
  • I have not been able to find the `mobile` character string in any user agent character string so far. Also, the trouble is that sometimes the web browser on the mobile electronic device may emulate the desktop mode, so the `android` character string does not show up. I could not test with the _Google Chrome_ web browser because it did not seem to work properly. The `android` character string did show up on the mobile electronic device while using the _Firefox_ web browser and the _web Browser_ web browser made by _Litter Penguin_. –  May 17 '17 at 18:43
  • Now that google cloud print has stopped its support. How do we handle this is android? – Amit Jun 01 '21 at 15:18
  • Are you using Google cloud print?I didn't understand this line... new cloudprint.Gadget(); – Eslam Sep 04 '22 at 19:05
4

⚠️ [Deprecated] : Google Cloud Print will no longer be supported as of December 31, 2020. Please see the support article for help migrating.

Use Google Cloud Print (GCP) - there is no app required. The user must have set up a printer via GCP though.

This example uses GCP gadget

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Print</title>
    </head>
    <body>
        <div>
            <p>On android devices (I have tested Nexus 5, Nexus 10, Galaxy S4 and Galaxy Tab 3) the window.print() command in javascript doesn't do anything, as far as I can tell it doesn't even register an error.</p>
            <p>I know for a fact that most if not all of these browsers can print because you can use mobile chromes menu to choose "print".  My questions is, why doesn't window.print() trigger the behavior you would expect (opening the clients print menu).
            And is there an android alternative to window.print()?</p>
        </div>

        <div id="gcpPrint"></div>

        <script src="https://www.google.com/cloudprint/client/cpgadget.js">
        </script>

        <script>
            var gadget = new cloudprint.Gadget();
            gadget.setPrintButton(cloudprint.Gadget.createDefaultPrintButton("gcpPrint"));
            gadget.setPrintDocument("text/html", "Print", document.documentElement.innerHTML);
        </script>
    </body>
</html>
Aakash
  • 21,375
  • 7
  • 100
  • 81
Avner
  • 4,286
  • 2
  • 35
  • 42
  • yea i installed google cloud print app, when i click the google cloud print button, the dialog box will open and i choose printer then click the print nothing happen. now what should i do? – Karthi Mar 03 '17 at 10:44
  • gcp is not avaiable by 2021 – Gabriel G Jan 19 '21 at 21:43
  • Now that google cloud print has stopped its support. How do we handle this is android? – Amit Jun 01 '21 at 15:18
0

I think, direct print() method is disabled on devices by default. I not saw so many phones or other Android devices with printer, however by USB it should be possible of course.

Instead, recommended is saving content/page as pdf and print it via some cloud print service.

Dudeist
  • 363
  • 1
  • 4
  • 13
  • 1
    Like I said, chrome for android has a "print" option in its menu. This has to be somehow accessible from javascript and as for converting to PDF could you possible elaborate on that. – MarshallOfSound Nov 02 '14 at 23:36
  • That's true. But this option is more for cloud print or "print to file" like a pdf or eps where "direct" print can be disabled. Here I found answer http://stackoverflow.com/questions/9268840/determine-whether-browser-supports-printing, can be many reasons why it not working in most of browsers on mobile devices, but in fact, it is just not implemented or disabled. Instead you can still print with share options or save as pdf etc – Dudeist Nov 02 '14 at 23:53
0

At this moment, window.print() functionality works perfectly on my Android 5.0.1 device with both, Chrome and the default browser.

Memet Olsen
  • 4,578
  • 5
  • 40
  • 50
0

Now, window.print() is working on Android devices.

UmAnusorn
  • 10,420
  • 10
  • 72
  • 100
Pravin
  • 17
  • 1
-6

Download adobe acrobat in your phone and you can use windows.print() in mobile.

Carljul
  • 111
  • 1
  • 4