我正在尝试为 google chrome 创建一个简单的扩展。我包括我使用过的代码。但包含的脚本不起作用。
index.html
<!doctype html>
<html>
<head>
<script src="ext.js"></script>
</head>
<body>
<button id='test'>Test</button>
<body>
</html>
manifest.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/