9

I have the following code:

<input type="button" value="Print" onclick="window.print(); return false;">

Which works in all browsers but it is doing nothing ( not opening print dialog box ) in ipad chrome browser.

How can I solve this problem?

However if I do manually print with chrome settings print then its working.

jerone
  • 16,206
  • 4
  • 39
  • 57
Navin Rauniyar
  • 10,127
  • 14
  • 45
  • 68
  • @NavinRauniyar - There's nothing wrong with your code. – Derek 朕會功夫 Jul 25 '14 at 04:26
  • But it's really not doing anything while I click button in ipad chrome browser. – Navin Rauniyar Jul 25 '14 at 04:27
  • This is actually a legitimate question and shouldn't really be downvoted. The fact that it is not printing is because you are viewing the page in a UIWebView. It should work in Safari though. – Derek 朕會功夫 Jul 25 '14 at 04:29
  • Yeah, it's working in safari. – Navin Rauniyar Jul 25 '14 at 04:30
  • 1
    It works in Safari (I also rechecked it myself). ASAIK there is no way to open the print dialog in Chrome in iOS ATM, since it uses a UIWebView to display webpages. – Derek 朕會功夫 Jul 25 '14 at 04:35
  • really... it would be pointless is it used a UIWebView as that would be using a form of embedded safari/webkit its there own browser they will have there own control for it more than likely it will use it for rendering but how chrome gets the content will all be it's own stuff im sure it should be opening google cloud print system – Barkermn01 Jul 28 '14 at 22:04
  • This was added in 2013: http://www.cnet.com/uk/news/chrome-for-ios-gets-wireless-printing-full-screen-browsing/ so it should open an option for cloud print and such dont see why it would not all it would be is adding a javascript handler to the UIWebView for window.print to call the native print handler from the menu. – Barkermn01 Jul 28 '14 at 22:12
  • Duplicates: http://stackoverflow.com/questions/4361119/ & http://stackoverflow.com/questions/21566052/ – jerone Aug 03 '14 at 16:41

3 Answers3

3

Multiple questions on SO show (1, 2, 3) that it's currently not possible to print in Chrome for iOS due to Apple's policy on using alternative browser engines.

Another solution is to use a third-party printing service: http://www.printfriendly.com

Community
  • 1
  • 1
jerone
  • 16,206
  • 4
  • 39
  • 57
1

It's a chrome bug/feature. window.print is available, it works and do nothing. Try this code:

try {
    window.print()
}catch(e) {alert(e.message)}

The alert will not be shown. Also class UIWebView can use UIKit Printing API

P.S. Chrome using UIWebView.

Alex
  • 11,115
  • 12
  • 51
  • 64
1

Try this:

function goPrint(){
    window.print();
    if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1) {
        window.location.reload();
    }
}
Alex
  • 11,115
  • 12
  • 51
  • 64
wayofthefuture
  • 8,339
  • 7
  • 36
  • 53