Oppdal
Oppdal

Reputation: 611

Javascript print blocked by chrome

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

Upvotes: 16

Views: 12000

Answers (5)

John McLear
John McLear

Reputation: 774

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

Upvotes: 0

corbacho
corbacho

Reputation: 9052

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

Upvotes: 1

bvaughn
bvaughn

Reputation: 13497

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.

Upvotes: 4

code_burgar
code_burgar

Reputation: 12323

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

Upvotes: 10

Riley Lark
Riley Lark

Reputation: 20890

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>

Upvotes: 6

Related Questions