Multi-Window Chrome Packaged App?

邮差的信 提交于 2019-12-01 01:41:07

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.

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