1
我的content.js,我從external_connectable網頁發送令牌 ,我在background.js.My中設置了該令牌,第二個content.js運行其他網頁,我調用了令牌我在background.js中設置了該標記。當令牌改變我聽onChanged方法,我給我newValue當我點擊按鈕。 當我點擊按鈕給我newValue但我的問題是當令牌更改,再次點擊給2令牌舊的和新的。當令牌再次改變給3值。Chrome.storage.onChanged存儲newValue,當我點擊
PS我的英語不好對不起那個
content.js(發送令牌background.js):
var x = localStorage.getItem("token");
chrome.runtime.sendMessage("dcjcfafcmfgklldlfehalaedlaaboemo",{data: x });
backgrond.js:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if (request.data)
chrome.storage.local.set({'token_data': request.data});
});
content.js(第二個網頁呼叫令牌):
$(document).ready(function() {
$(".info-more").append($("<a class='my-button'></a>"));
chrome.storage.onChanged.addListener(function(changes, namespace) {
$('.my-button').on('click',function(){
console.log(changes.token_data);
});
});
});
感謝:
只需推動單擊處理消息監聽器外:
第二content.js –