简体   繁体   中英

printing support on chrome packaged apps

I can't seem to find any example of window.print() support in chrome packaged apps - can someone please post an example?

I'm using this

function clickHandler(e) {
  window.print();
}
document.addEventListener('DOMContentLoaded', function () {
  document.querySelector('button').addEventListener('click', clickHandler);
});

from "Hello World!" sample platform app, but I can't seem to get it working.

is there a special permission settings I should use?

Thanks!

Yes, window.print() works in Chrome Apps. You can find a sample in the official samples repo .

It is as simple as calling window.print() in any DOM window of your app:

  // prints the content of the current window:
  window.print();

  // prints the content of another AppWindow:
  anotherAppWindow.contentWindow.print()

AppWindow is the Chrome Apps object that encapsulates and extends the actual DOM window with app capabilities. This object can be obtained by either:

  1. saving the parameter from the callback of chrome.app.window.create

  2. calling chrome.app.window.current() on any code running in the context of the desired window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM