简体   繁体   English

如何在单击按钮时将html扩展为带有chrome扩展名的网页

[英]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.

相关问题 如何使用Chrome扩展程序向网页注入按钮 - How to inject a button to a webpage with Chrome Extension 如何通过 Chrome 扩展将 CSS 注入网页? - How to inject CSS into webpage through Chrome extension? 如何通过将侦听器添加到“窗口”来从Chrome扩展程序单击网页上的按钮? - How to click a button on a webpage from Chrome extension by adding a listener to `window`? 使用iframe通过Chrome扩展程序将本地HTML文件注入网页? - Inject local HTML file into webpage via Chrome Extension using iframe? 如何使用 chrome 扩展程序在网页中注入模板组件? - How to inject a stencil's component inside a webpage using a chrome extension? 如何单击 Chrome 扩展程序中的按钮 - How to click on a button in Chrome Extension Chrome.tabs.executeScript(); + .addEventListener(“ click”,…); 通过chrome扩展程序将代码注入活动网页 - Chrome.tabs.executeScript(); + .addEventListener(“click”, …); to inject code into active webpage through chrome extension 如何在Chrome控制台中单击网页中的按钮? - how to click a button in a webpage from chrome console? 如何从点击按钮运行 chrome 扩展程序? - How to run a chrome extension from a click button? 获取当前选项卡 html 元素上的按钮单击 chrome 扩展 - Get current tab html element on button click in chrome extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM