[英]How to inject html into webpage with chrome extension on button click
I have this in my popup.html 我在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>
This is my popup.js so far... 到目前为止,这是我的popup.js ...
function dothis(){
/* ??? */
};
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('button').addEventListener('click', dothis);
});
I want to inject a bit of html code into the web page on button click; 我想在单击按钮时向网页中注入一些html代码; I've already included it in my manifest. 我已经将其包含在清单中。 How do I do this? 我该怎么做呢? Sorry, I'm new to this! 抱歉,我是新来的! I've looked around on stack overflow, but I could really understand any of the answers. 我四处查看堆栈溢出,但是我真的可以理解任何答案。 Thanks in advance! 提前致谢!
You need a Content Script in order to interact with the page. 您需要一个内容脚本才能与页面进行交互。 You can send a message from the popup to the content script with Messaging , then the content script can do the actual interaction with the page. 您可以使用Messaging将消息从弹出窗口发送到内容脚本,然后内容脚本可以与页面进行实际交互。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.