问题
Hello I'm new to chrome packaged apps. How would I create a button image, that when clicked launches a new chrome packaged app window displaying a local html page.
回答1:
In your first html page, just add the button. Also, that page will need to reference a Javascript file to add the event handlers:
<button id="thebutton">Open a New Window</button>
<script src="script.js"></script>
Then you add an event handler to the button in script.js
(or whatever you name your script page):
document.querySelector('#thebutton').addEventListener('click', function() {
chrome.app.window.create('new.html', {"width":300, "height": 200});
});
If you need for that window to be sandboxed (e.g., not use the default content security policy), you need to specify that the page is sandboxed in manifest.json
:
"sandbox": {
"pages": ["new.html"]
}
When new.html
is loaded, it will be loaded in its own origin which doesn't have access to the opening window or to the advanced API's. If you need the sandboxed page to do something with the advanced API's, you can use postMessage
and receive messages to communicate with a window that's still in the CSP.
来源:https://stackoverflow.com/questions/15752860/multi-window-chrome-packaged-app