最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome extension: Access to variables of a background.js from a popup.js - Stack Overflow

programmeradmin1浏览0评论

If I'm using chrome.extension.getBackgroundPage(), I can access variables of the background.js like this:

background.js:

var transfer = 'some text';

popup.js:

chrome.extension.getBackgroundPage().transfer

But this says I get only a window object (but maybe 'JavaScript' before 'window' means something...). How can I access background variables?

If I'm using chrome.extension.getBackgroundPage(), I can access variables of the background.js like this:

background.js:

var transfer = 'some text';

popup.js:

chrome.extension.getBackgroundPage().transfer

But this says I get only a window object (but maybe 'JavaScript' before 'window' means something...). How can I access background variables?

Share Improve this question edited Dec 22, 2016 at 21:35 Jacob 2,1541 gold badge13 silver badges20 bronze badges asked Mar 22, 2013 at 14:18 dortonwaydortonway 4391 gold badge5 silver badges19 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 18

Yes, the word 'javascript' before window does mean that its returning the javascript file(page) background.js

For ease of access at the top of my popup.js file I do this:

var background = chrome.extension.getBackgroundPage(); //do this in global scope for popup.js

then you can do this:

background.transfer;

Since you typically have to access your background page a lot, this just makes life easier all around.

发布评论

评论列表(0)

  1. 暂无评论