【问题标题】:DOMContentReady is not being fired in a Chrome extensionDOMContentReady 未在 Chrome 扩展程序中触发
【发布时间】:2012-12-27 02:16:09
【问题描述】:

我在 manifest.json 文件中写了如下代码:

{
   "name":"SecondExtension",                     
   "version":"1.0",
   "manifest_version":2,
   "content_security_policy": "script-src 'self';object-src 'self'",
   "permissions":["tabs", "http://*/*", "https://*/*"],
   "browser_action": {
          "defaul_icon":"icon.png",
          "default_title":"Security" ,
          "default_popup":"pops.html"
   }
}

我在pops.html中写了如下代码

<html>
<head>
<script src='popup.js'>
</script>
</head>
<body>

<p>Username : </p></br><input type="text"  id="name" height="20" width="50" />

<p>Password :</p></br> <input type="password"  id="password" height="20" width="50" />

<a href="pops2.html">login</a>
<button id="login">login</button>
<textarea id="return_name" rows="2" columns="20"></textarea>
</body>
</html>

popup.js 中的代码是:

function check() {
    alert('its working');
}
document.addEventListener('DOMContentReady', function () {
    document.getElementById('login').addEventListener('click', check);
});

现在的问题是 JavaScript 没有像我点击登录按钮时那样运行,它没有提醒消息“它正在工作”。我在这里错过了什么?

【问题讨论】:

    标签: javascript google-chrome google-chrome-extension domready


    【解决方案1】:

    AFAIK,没有 DOMContentReady 事件,有 DOMContentLoaded

    尝试用这个替换你的代码 -

     function check() {
        alert('its working');
     };
     document.addEventListener('DOMContentLoaded', function () {
        document.getElementById('login').addEventListener('click', check);
     });
    

    【讨论】:

      猜你喜欢
      • 2012-03-25
      • 2014-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多