Javascript 无法在 google chrome 扩展中工作

标签 javascript google-chrome google-chrome-extension

我正在尝试为 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/

相关文章:

google-chrome - Chrome、tabindex 和单选按钮的问题

java - 哪个用户在 Linux 中使用 java 中的进程启动?

javascript - Chrome 内联插件安装在 window.confirm 上

javascript - 如何在Jquery中为同一类的不同div中的特定元素添加悬停效果?

javascript - 延迟加载不适用于 div

javascript - 输出未定义

javascript - JavaScript 中的函数顺序

javascript - Chrome 扩展内容调用后台回调但参数未定义

google-chrome - 带有新浏览器选项卡的 chrome.tabs.executeScript 无法正常工作?

javascript - 在新的 Chrome 窗口中打开多个标签页