多窗口Chrome打包应用程序

多窗口Chrome打包应用程序

本文介绍了多窗口Chrome打包应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好我是新来的Chrome打包应用程序。
如何创建一个按钮图片,点击时启动
a显示本地html页面的新Chrome打包应用程序窗口。

/ div>

在第一个html页面中,只需添加按钮即可。另外,该页面需要引用一个Javascript文件来添加事件处理程序:

 < button id =thebutton> ;打开一个新窗口< / button> 
< script src =script.js>< / script>

然后,您将事件处理程序添加到 script.js (或任何你命名你的脚本页面):

  document.querySelector('#thebutton')。addEventListener ('click',function(){
chrome.app.window.create('new.html',{width:300,height:200});
});

如果您需要对该窗口进行沙盒处理(例如,不使用默认内容安全策略),您需要指定页面在 manifest.json 中的沙箱:

 sandbox:{
pages:[new.html]
}

加载 new.html 时,它将被加载到它自己的原始位置,该位置无法访问开启窗口或高级API。如果您需要沙盒页面来处理高级API,您可以使用 postMessage 并接收消息与仍在CSP中的窗口进行通信。


Hello I'm new to chrome packaged apps.How would I create a button image, that when clicked launchesa new chrome packaged app window displaying a local html page.

解决方案

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.

这篇关于多窗口Chrome打包应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 02:08