我的chrome扩展程序需要检查扩展程序处于活动状态的页面上popup.html上是否已选中复选框。
content.js:
$(document).ready(function () {
time = setInterval(function () {
if(true){
//check if checkbox is checked??
}
}, 500);
});
popup.html:
<!doctype html>
<html>
<head>
<input type="checkbox" name="thingToDo" value="isChecked"> Do thing<br>
</body>
</html>
是否有一种方法可以从content.js中抓取popup.html?还是我需要background.js和某种来回发送的消息?
答案 0 :(得分:0)
您无法在popup.html
和content.js
之间进行直接通信,但是通常的方法是使用chrome.storage API。
通过checked
设置popup.html
状态,并监听content.js
中的存储更改。
因此,无论何时或从何处更改存储值,您都将进入content.js
这也是简便方法。