I am facing a really weird problem. I am calling window.print() from a javascript file. This is working fine in Safari, IE, Firefox... and until two hours ago it worked in Chrome, too. (Version 29.0.1547.57)
I did not change anything essential in my javascript file (really - I just removed some comments...), but what now happens is really weird: In Chrome, the print dialogue does not open when window.print() is called. Nothing happens. But then, when I press reload, the print dialogue opens immediately.
The behaviour in the other browser did not change. And while debugging in Chrome I can see that window.print() is called as expected and the script goes on after that. Only the print dialogue is not shown until pressing reload.
Has anybody ever experienced something like that? I also tried to call window.print() in setTimeout(), but this did not change anything. When I debug the content of the page which shall be printed appears to be perfectly loaded.
I am sorry to ask, but I did not find anything while researching. Any help would be appreciated!
Thank you!
The window. print() method calls the browser's build in print support plugin to print the current DOM page. you can check the documentation, it doesn't support any argument or settings. to setup the print, you can only utilize the browser's GUI( ex. enable or disable background graphics etc.)
print() Opens the print dialog to print the current document. If the document is still loading when this function is called, then the document will finish loading before opening the print dialog.
There are two ways to get to the system print dialog from Chrome. If you've already pressed the Ctrl+P keyboard shortcut, then look for the 'Print using system dialog' option at the very bottom of the left column. What is this? To jump directly to the system print dialog, you can use the Ctrl+Shift+P keyboard shortcut.
Wasiim is right, there is a Chrome bug where window.print()
does not work when there is a <video>
tag in the DOM. I solved it by calling this function:
function printPage() { window.print(); //workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633 if (window.stop) { location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear window.stop(); //immediately stop reloading } return false; }
From my experience this is due to continued background traffic, e.g. ajax calls and the like that prevent Chrome from feeling the that page is loaded completely. The reload breaks all traffic and thus the print dialog pops up. This is a particular gotcha in Visual Studio 2013 where BrowserLink continually ticks away in the background. This can be tested by disabling BrowserLink via the setting below:
<configuration> <appSettings> <add key="vs:EnableBrowserLink" value="false"/> </appSettings> </configuration>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With