我正在尝试构建我的第一个chrome扩展,并且很难从popup.js发送消息到work.js.任何帮助都非常感谢。
Popup.js脚本
var but = document.getElementById('ok_btn');
if (but )
{
but.addEventListener("click", saveChanges , false);
}
function saveChanges() {
var username = document.getElementById('username').value;
alert(username);
chrome.runtime.sendMessage({ website: username,
message:"Username_Received"});
chrome.tabs.executeScript({file: 'work.js'});
window.close();
}
Work.js
chrome.runtime.onMessage.addListener(function(request,sender,sendResponse){
console.log('reached');
alert('inside message request');
if(request.website == "Username_Received"){
alert(request.website);
}
});