我正在尝试使用chrome.storage.local.set
将变量从chrome扩展名pop / js移至另一个.js文件。当我在通话功能中显示警报时,它会起作用。但是,只要我在get函数之外执行警报,它就会显示undefined
。关于我为什么无法弄清楚的任何猜测?
var sendOffer = "";
var items = [];
var status = false;
function shareCloset() {
sendOffers = chrome.storage.local.get('sendOffers', function (items) {
sendOffers = items.sendOffers;
var closet = [];
closet = $(".tile");
//alert(sendOffers); IT WILL DISPLAY THE RIGHT NUMBER HERE!
alert(closet[0].id);
var url = closet[0].firstChild.pathname;
alert(url);
window.location.href = url;
});
alert(sendOffers); //RETURNS UNDEFINED
}