cmpscabral
cmpscabral

Reputation: 183

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!

Upvotes: 4

Views: 2678

Answers (1)

mangini
mangini

Reputation: 4259

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

Upvotes: 3

Related Questions