I
I
Igor2016-09-08 22:31:39
JavaScript
Igor, 2016-09-08 22:31:39

Why doesn't click listener work in chrome extensions?

//poupop.js
document.addEventListener('DOMContentLoaded',function(){
    
var clickClearLocal= document.getElementById('btnClearLocalStr');


clickClearLocal.addEventListener('click',function(){
    alert('r');
 //   chrome.storage.local.remove('channels');
        
  
    
},false);

});

<!doctype html>
<html>
  <head>
     <meta charset="utf-8">
    <title>Потерянное время LostTime</title>
  <link href="css.css" rel="stylesheet" type="text/css"/> 
  </head>
  <body>
  <div id="options"><!-- меню -->
<h3>first app</h3>
<div id="btnClearLocalStr">
    Очистить буфер 
</div>
</div>
<div id="dannie"></div> <!-- в этот блок буду загружать данные, которые будут показываться пользователю-->
    <script src="popup.js"></script><!-- скрипт, выполняющийся при нажатии на иконку расширения-->
  </body>
</html>

{
  "manifest_version": 2,
  "name": "Help Panda",
  "version": "2.0",
  
  "icons": {
    "128": "panda.png"
  },
  "content_scripts": [
    {
      "matches": [ "*://*/*" ],
      "js": [ "content.js" ]
    }
  ],

  "background": {
    "scripts": ["background.js"]
  },
  "permissions": [
    "webNavigation",
    "notifications",
    "tabs",
      "storage"
  ],
      "browser_action": {
        "default_title": "Help Panda",
        "default_icon": "panda.png",
        "default_popup": "popup.html"
    }
  
}

I click and he doesn't respond.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rou1997, 2016-09-09
@Rou1997

You have a link to the script at the very end of the DOM tree ( body), so DOMContentLoaded does not work at all, it's strange that you didn't guess to debug it, you need it when the link is in head, either do it without it, or move the link to head.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question