I have written the following code in manifest.json file:

{
   "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"
   }
}

And I have written the following code in 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>

And the code in popup.js is :

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

Now the problem is JavaScript is not running as in whenever I click on login button it's not alerting the message "it's working" . what have I missed here?

有帮助吗?

解决方案

AFAIK, there is no DOMContentReady event, there is DOMContentLoaded

Try replacing your code with this -

 function check() {
    alert('its working');
 };
 document.addEventListener('DOMContentLoaded', function () {
    document.getElementById('login').addEventListener('click', check);
 });
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top