manifest.json
{ "name": "Printing Window Example App", "short_name": "Printing App", "description": "Example app for printing it's screen", "version": "0.1", "manifest_version": 2, "app": { "background": { "scripts": ["background.js"] } }, "icons": { "128": "128.png" } }
background.js
chrome.app.runtime.onLaunched.addListener(function() { chrome.app.window.create('main.html', { 'bounds': { 'width': 400, 'height': 500 } }); });
main.html
<!DOCTYPE html> <html> <head> </head> <body> <div>Printing Example</div> <button id="btn_print">Print this screen</button> <table border="1"> <thead> <tr> <th>Name</th> <th>Symbol</th> <th>Market</th> <th>Price</th> <th>Change</th> <th>Volume</th> </tr> </thead> <tbody> <tr> <td>Google Inc.</td> <td>GOOGL</td> <td>NasdaqGS</td> <td>605.11</td> <td>4.18%</td> <td>4,874,260</td> </tr> <tr> <td>Apple Inc.</td> <td>AAPL</td> <td>NasdaqGS</td> <td>94.43</td> <td>1.44%</td> <td>49,987,593</td> </tr> <tr> <td>Amazon Inc.</td> <td>AMZN</td> <td>NasdaqGS</td> <td>358.66</td> <td>1.76%</td> <td>3,410,032</td> </tr> </tbody> </table> <img src="128.png"></img> </body> <script src="app.js"></script> </html>
app.js
document.getElementById("btn_print").onclick = function(){ // print app's screen. window.print(); }
Chromeアプリだからといって特に特別なことはなくて、他のJavascriptアプリと同じように
window.print()
すれば良いだけです。
0 件のコメント:
コメントを投稿