我在popup.html中有这个

<!DOCTYPE html>
<html>
<body>
     <button id="button">Starting Now</button>
     <script src="jquery-2.1.4.min.js" type='text/javascript'></script>
     <script src="popup.js" type='text/javascript'></script>
  </body>
</html>


到目前为止,这是我的popup.js ...

function dothis(){
  /* ??? */
};

document.addEventListener('DOMContentLoaded', function () {
    document.getElementById('button').addEventListener('click', dothis);
});


我想在单击按钮时向网页中注入一些html代码;我已经将其包含在清单中。我该怎么做呢?抱歉,我是新来的!我四处查看堆栈溢出,但是我真的可以理解任何答案。提前致谢!

最佳答案

您需要Content Script才能与页面进行交互。您可以使用Messaging将消息从弹出窗口发送到内容脚本,然后内容脚本可以与页面进行实际交互。

10-05 20:53
查看更多