gpt4 book ai didi

Javascript 无法在 google chrome 扩展中工作

转载 作者:行者123 更新时间:2023-11-28 01:15:17 25 4
gpt4 key购买 nike

我正在尝试为 google chrome 创建一个简单的扩展。我包括我使用过的代码。但包含的脚本不起作用。

index.html

<!doctype html>
<html>
<head>
<script src="ext.js"></script>
</head>
<body>
<button id='test'>Test</button>
<body>
</html>

ma​​nifest.json

{
"name": "Demo Extension",
"description": "Demo Extension",
"version": "1.0",
"permissions": ["tabs", "http://*/*", "https://*/*"],
"browser_action": {
"default_title": "Demo",
"default_popup": "index.html"
},
"content_security_policy":"script-src 'self' https://localhost; object-src 'self'",
"manifest_version": 2
}

ext.js

function clickHandler(e) {
alert('its working');
}

document.addEventListener('DOMContentReady', function () {

document.querySelector('button')
.addEventListener('click', clickHandler);
});

我该如何解决这个问题?

最佳答案

它是 DOMContentLoaded 而不是 DOMContentReady - devnull69

关于Javascript 无法在 google chrome 扩展中工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23909067/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com