繁体   English   中英

在content.js(Chrome扩展程序)中发生操作时,如何检查popup.html页面?

[英]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.htmlcontent.js之间进行直接通信,但通常的方法是使用chrome.storage API。

通过popup.html设置checked状态,并监听content.js存储更改。

因此,无论何时何地更改存储值,您都可以进入content.js

这也是简单方法和干净方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM