![](/img/trans.png)
[英]Chrome extension messaging between popup.html and content.js
[英]How to check popup.html page when action occurs within content.js (Chrome Extension)?
我的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和某种来回发送的消息?
您无法在popup.html
和content.js
之间进行直接通信,但通常的方法是使用chrome.storage API。
通过popup.html
设置checked
状态,并监听content.js
存储更改。
因此,无论何时何地更改存储值,您都可以进入content.js
这也是简单方法和干净方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.