铬扩展如何单击活动页面上的按钮?
网上有平淡无奇的网页。页面上有带有特定ID的按钮类型的简单元素。还有一个带有按钮的Chrome扩展。我想单击“扩展”按钮,然后依次单击“页”按钮。
var someElement = document.getElementById('someElement');
someElement.addEventListener('click', function () {
// here I'd like to click on a button with specific ID.
});
我是新的,但我试图创建一个铬的扩展,以操纵在网页上的王国。目前,我有两个按钮,每个按钮将执行不同的任务。下面的内容有意义吗?另外,如果我有多个内容脚本,如何将它们添加到manifest.json中?
popup.js:
function injectTheScript() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// query the active tab, which will be only one tab
//and inject
我试图将这些值输入到新选项卡上的元素中,然后单击submit登录。我尝试过许多不同的方法,但似乎无法让它发挥作用。
function injectScript(){
var script = ' var e = document.getElementById("email"); var p = document.getElementById("password");'+
'e.value ="'+currentEmployee.email+'"; p.value = "
当点击get数据按钮时,我想显示我在后台拥有的数组数据,但是当我单击该按钮时什么也不做,这对于chrome来说非常新。谢谢。
manifest.json:
{
"name":"modz",
"manifest_version":2,
"version":"1.0",
"description":"this ext. will help you record all the urls you have visited",
"backgr
据我所知,我找不到一个答案(互联网和堆栈溢出):当你有你的chrome扩展,并且你的content.js代码在网页/DOM中插入了一些HTML代码,你如何添加图像?
我尝试了以下方法,但不起作用-图像出现,但损坏(它必须加载吗?如果是,如何实现?)。
document.getElementById("header").insertAdjacentHTML("afterend", "<div><img src='myimage.jpg'>This text has been added</div>"
我有popup.js
function registerButtonAction(tabId, button, action) {
// clicking button will send a message to
// content script in the same tab as the popup
button.addEventListener('click', () => chrome.tabs.sendMessage(tabId, { [action]: true }));
}
function setupButtons(tabId
为什么chrome.app.isInstalled总是为Google扩展返回false?
动态地,我在页面加载时添加了一个链接元素:
<link type="text/css" rel="chrome-webstore-item" href="https://chrome.google.com/webstore/detail/itemID">
以下是一些在单击按钮时执行的Javascript:
if (!chrome.app.isInstalled) {
alert('extension is about to be ins