1

I have 2 JavasScript files for my Chrome Packaged App.

1. background.js is a main JavaScript file that called by manifest.json

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 is a controller of index.html

Question: Can I call variable "foo" or function "bar" from background.js in app.js?

PS. Or have any solution to transfer value between page such as chrome.storage ?

iamcmnut
  • 459
  • 1
  • 5
  • 9
  • possible duplicate of [How do I get data from a background page to the content script in google chrome extensions](http://stackoverflow.com/questions/4700254/how-do-i-get-data-from-a-background-page-to-the-content-script-in-google-chrome) – Qantas 94 Heavy Sep 24 '13 at 07:20

1 Answers1

5

In your app.js you can get the background page like this:

chrome.runtime.getBackgroundPage(function(page) {
    page.foo;
    page.bar(2, 2);
});
Mr. Newb
  • 96
  • 2