【发布时间】:2020-10-17 19:54:07
【问题描述】:
我正在尝试创建一个 chrome 扩展程序,当您单击扩展程序上的按钮时,它将单击 Google 文档上的按钮。下面是我对这个问题的尝试(这似乎不起作用,我只是点击文档上的打印按钮)。
manifest.json
{
"manifest_version": 2,
"name": "Google Docs Button Click",
"description": "Google Docs Button Click Simulator",
"version": "1.0",
"permissions": ["tabs", "http://*.docs.google.com/*","*://*/*"],
"browser_action": {
"default_icon": "cursor.png",
"default_popup": "popup.html"
}
}
popup.html
<!doctype html>
<html>
<head><title>activity</title></head>
<body>
<button id="clickactivity">click</button>
<script src="popup.js"></script>
</body>
</html>
popup.js
function injectTheScript() {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.executeScript(tabs[0].id, {file: "content_script.js"});
});
}
document.getElementById('clickactivity').addEventListener('click', injectTheScript);
content_script.js
function clickButton() {
var buttons = document.getElementById("printButton");
buttons.click();
}
clickButton();
请帮忙。
【问题讨论】:
标签: javascript html google-chrome google-chrome-extension content-script