2013-09-24 36 views
1

我的Chrome包装应用程序有2个JavaScript文件。

1. background.js是通过manifest.json的称为主JavaScript文件我可以在Chrome Packaged App的背景页面调用变量或函数吗?

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 
    } 
    }); 
}); 

2. app.js是的index.html控制器

问:我可以叫变量“foo”或函数“bar”from background.js in app.js

PS。或者有任何解决方案来传输页面之间的值,如chrome.storage

+0

可能重复(HTTP:/ /stackoverflow.com/questions/4700254/how-do-i-get-data-from-a-background-page-to-the-content-script-in-google-chrome) –

回答

4

在你app.js你可以得到后台页面如下:

chrome.runtime.getBackgroundPage(function(page) { 
    page.foo; 
    page.bar(2, 2); 
}); 
的[我如何从后台页面数据,谷歌浏览器的扩展内容脚本]
相关问题