16

I'm trying to run a javascript window.print() from chrome. It prints the first time but then subsequent calls (within a minute of the first call) fail. The chrome log states "Ignoring too frequent calls to print()."

     window.print();
 setInterval(function() {
     window.print();
 }, 5000);

Can't find a way around this issue. Any ideas?

Thanks in advance

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Oppdal
  • 591
  • 3
  • 7
  • 15
  • 1
    Works for me, Chrome 9. It prints each 5 seconds, I get that message though. It seems to fail when the dialog is already open by the way: http://jsfiddle.net/bBzAb/. – pimvdb Mar 12 '11 at 13:22
  • 1
    Why on earth would you do something like that? – Pointy Mar 12 '11 at 13:29
  • 1
    I’m not, the script is merely to replicate this issue. My app contains a button to instigate 'print' – Oppdal Mar 12 '11 at 13:34
  • 5
    That seems like a bad decision on behalf of Google. I wonder when printing too much has actually been a problem justifying these measures. – Teekin Apr 18 '11 at 18:56

5 Answers5

10

It appears to be a design decision rather than a bug. Getting around it will probably be pretty hard.

code_burgar
  • 12,025
  • 4
  • 35
  • 53
  • Thanks, I've since added a browser-check to see if agent's chrome, a counter & a timer. If they click the button > once within a minute I've got a subtle message that appears to ask them to Ctrl+P / menu print if nothing happens. – Oppdal Mar 12 '11 at 14:02
6

Sounds like a deliberate choice on Chrome's part that you probably won't be able to get around. As an alternative, you could prepare all of your jobs at once and separate them with a page break:

<div style="page-break-after:always"></div>

Riley Lark
  • 20,660
  • 15
  • 80
  • 128
4

I have found the following to be a work-around to enable JavaScript printing from Chrome:

<a href="#" onclick="window.print(); return false;">Click me to Print</a>

It seems that adding the "return false" bit to the onclick handler makes Chrome happy.

I think that without it, Chrome attempts to follow the link somewhere / reload the page. This results in a print dialog showing nothing to print.

bvaughn
  • 13,300
  • 45
  • 46
  • I'm not going to down-vote. But the question is about "multiple and frequent calls to window.print", not about how to enable printing. The 'return false' didn't work to prevent this behavior (Chrome v.22) – corbacho Oct 15 '12 at 10:46
1

Good! Bug fixed. The bug was fixed as part of v.23 if I'm not wrong.

So if the release cycle is every 6 weeks and Chrome 22 was released 25th of Sep, then by 6th of November (aprox.) the fix will be in the Chrome Stable version

corbacho
  • 8,762
  • 1
  • 26
  • 23
0

In chrome you have to fire the window.location.reload event to fire a print event.. ref from Chrome: window.print() print dialogue opens only after page reload (javascript)

This works for me..

window.print();
if(navigator.userAgent.toLowerCase().indexOf('chrome') > -1){
  window.location.reload();
}
Community
  • 1
  • 1
John McLear
  • 764
  • 1
  • 10
  • 20