iam*_*nut 1 html javascript google-chrome-app
我的 Chrome Packaged App 有 2 个 JavaScript 文件。
1. background.js 是一个由 manifest.json 调用的主要 JavaScript 文件
var foo = 'sss';
function bar(a,b) {
return a+b;
}
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('index.html', {
bounds: {
width: 500,
height: 300
}
});
});
Run Code Online (Sandbox Code Playgroud)
2. app.js 是 index.html 的控制器
问题:我可以在app.js 中从background.js调用变量“foo”或函数“bar”吗?
附注。或者有什么解决方案可以在页面之间传输价值,例如chrome.storage?
小智 5
在你的 app.js 你可以得到这样的背景页面:
chrome.runtime.getBackgroundPage(function(page) {
page.foo;
page.bar(2, 2);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
639 次 |
| 最近记录: |