0

Bit of an odd question, and I'm perfectly willing to accept that this just isn't possible, but is there a way of using jQuery or just normal JavaScript to check if a device is capable of printing?

We currently have a button on our article pages that allow the user to click in order to print the page. However on some Android devices the "javascript:window.print();" function just doesn't work.

I was just wondering if there was a way of performing a check to seeing if the device supports this?

Liam Richardson
  • 138
  • 1
  • 12

2 Answers2

3

You can use feature detection for this:

if('print' in window){
  window.print();
} else {
  alert("Printing is not supported on this device");
}
Rob M.
  • 35,491
  • 6
  • 51
  • 50
1

Basically, Javascript has no way to know if the device can print. After all, this mostly depends on it being connected to a printer. But you could check if the function window.print is defined like this

if(typeof window.print == 'function') {
    //at least the function is available
}
Lars Ebert
  • 3,487
  • 2
  • 24
  • 46