我想做一個簡單的擴展,它將一個變量從背景傳遞給彈出窗口。問題是,我得到'未定義'的迴應。將變量從背景傳遞到Chrome擴展上彈出
清單:
{
"name": "Get var",
"description": "get var",
"version": "2.0",
"permissions": [
"activeTab"
],
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
"default_title": "Get that variable",
"default_popup": "popup.html"
},
"manifest_version": 2
}
background.js
var myURL = 'aaa';
popup.html
<!doctype html>
<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
popup.js
document.addEventListener('DOMContentLoaded', function() {
var bg = chrome.extension.getBackgroundPage();
var myURL = bg.myURL;
alert(myURL)
});
嘗試'window.myURL ='aaa';'在background.js – rsanchez