Use System Print Dialog in Chrome in JavaScript

混江龙づ霸主 提交于 2019-12-19 06:44:11

问题


We have an issue where Chrome's "Print Preview" does not print our pages correctly. If you use the "Use System Print Dialog link" (Ctrl+Shift+P), it prints our page fine (almost identically to Firefox).

We have a button on our page that calls window.print() to open the print dialog. However, in Chrome it opens to the "Print Preview" dialog which ends up not printing our page correctly.

Is there away with JavaScript to print directly to the "system print dialog" in Chrome?

P.S. I do know how the end user can disable the Print Preview in chrome://flags, but what I want to know is there anyway to prevent it from showing when I programmatically call window.print() (or similar) regardless of user settings.


回答1:


Print dialogs are not scriptable using JavaScript. They're proprietary parts of browsers themselves.




回答2:


Hi i am facing the same issue... I even tried firing keyboard event ctrl+shift+P from my script in order to show system print dialog.

You can fire a keyboard event and that issue is successfully dispatched, however the value of keyCode that the browser receives is always 0 (instead of ASCII value of ‘P’)

There is a bug logged https://bugs.webkit.org/show_bug.cgi?id=16735 against webkit for the same… and here are some posts http://code.google.com/p/chromium/issues/detail?id=27048, http://code.google.com/p/chromium/issues/detail?id=52408 mentioning the same issue in Safari and Chrome…



来源:https://stackoverflow.com/questions/9470066/use-system-print-dialog-in-chrome-in-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!