【发布时间】:2021-06-11 15:22:17
【问题描述】:
创建 chrome 扩展,在新标签中打开链接并尝试单击新打开的标签上的按钮 -
我可以使用扩展打开新标签,但内容脚本没有在新标签上执行。
清单文件
{
"manifest_version": 2,
"name": " New Tab Launcher",
"description": "Create the tab and button click ",
"version": "1.0",
"icons": {
"16": "icon.png",
"48": "icon.png",
"128": "icon.png"
},
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"activeTab",
"tabs"
],
"content_scripts": [
{
"matches": [
"http://*/*", "https://*/*"
],
"js": [
"jquery-3.6.0.slim.min.js","contentScript.js"
],
"run_at": "document_end"
}
]
}
popup.js
document.addEventListener('DOMContentLoaded', function() {
var checkPageButton = document.getElementById('addMeetingUrl');
checkPageButton.addEventListener('click', function() {
chrome.tabs.create({'url': "youtube.com"});
}, false);
}, false);
contentScript.js
alert("This is test");
$(document).load(function (e) {
alert("Testing content script" +$('#logo').text());
});
在上面第一个警报成功通过下一个脚本没有启动。
我已尝试删除 $(document).load 并添加 $(document).ready 两者都不适合我。
【问题讨论】:
标签: javascript google-chrome-extension