title: Execute script after click in popup.html (chrome extension)
body: <p>I am trying to execute javascript on a page when I click on a button in <code>popup.html</code>. I tried to use such a way:</p>
  
  <p>In <strong>background.js</strong>:</p>
  
  <pre><code>chrome.tabs.onUpdated.addListener(function(tabId, changeInfo){
      if(changeInfo.status == "loading") {
          insert(tabId);
      }
  });
  function insert(tabId) {
      chrome.tabs.get(tabId, function(tab) {
          $('button').click(function() {
              chrome.tabs.executeScript(tab.id, {file: 'js/alert.js'});
          });
      });
  }
  </code></pre>
  
  <p>Alert.js consists only of one string: <code>alert('works');</code></p>
  
  <p>Alert is just an example. Real script should do some DOM manipulation with opened tab after user clicks on a button im popup.html.</p>