title: Simple Chrome Content Script Not Running
body: <p>I wrote a short content script, which stops a particular site from creating new windows for link clicks.</p>
  
  <p>This is my first Chrome extension, and I've scored this website and the internet for a reason why it won't run, but I can't find any. I'm probably making a fundamental amateur mistake somewhere.</p>
  
  <p>Manifest.json:</p>
  
  <pre><code>{
  "manifest_version": 2,
  
  "name": "DHS Links",
  "description": "Stops the school's site from constantly opening new windows.",
  "version": "1.0",
  
  "browser_action": {
  "default_icon": "icon.png"
  },
  
  "content_scripts":[
    {
      "matches": ["*://www.darienps.org/dhs/*"],
      "js": ["jquery.js", "makeNormalLinks.js"],
      "run_at": "document_end"
  
    }
   ]
  }
  </code></pre>
  
  <p>I tested the Javascript file by itself on a local version of the site, so I'm pretty sure it's fine, but just in case:</p>
  
  <p>makeNormalLinks.js:</p>
  
  <pre><code>$(document).ready(function() {
      $("a").each(function(){
          $(this).removeAttr("onclick");
      });
  });
  </code></pre>
  
  <p>A copy of jQuery is in the same directory and doesn't seem to have any issues.</p>
  
  <p>Here's the onclick code for many links on the website:</p>
  
  <p><code>onclick="window.open(this.href,'targetWindow','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,')
  </code></p>
  
  <p>Thank you for looking this over!</p>
  
  <hr>
  
  <p>Edit:</p>
  
  <p>I tried two of the injection methods from <a href="https://stackoverflow.com/questions/9515704/building-a-chrome-extension-inject-code-in-a-page-using-a-content-script">Rob W's response to another question</a> linked to in the comments by Teepeemm.</p>
  
  <p>Here's the new code for Method 1:</p>
  
  <p>Manifest.json:</p>
  
  <pre><code>{
  "manifest_version": 2,
  
  "name": "DHS Links",
  "description": "Stops the school's site from constantly opening new windows.",
  "version": "1.0",
  
  "browser_action": {
  "default_icon": "icon.png"
  },
  
  "content_scripts":[
    {
      "matches": ["*://www.darienps.org/dhs/*"],
      "js": ["jquery.js", "scriptLauncher.js"]
  
    }
   ],
  "web_accessible_resources": ["makeNormalLinks.js"]
  }
  </code></pre>
  
  <p>scriptLauncher.js:</p>
  
  <pre><code>var s = document.createElement('script');
  // TODO: add "script.js" to web_accessible_resources in manifest.json
  s.src = chrome.extension.getURL('makeNormalLinks.js');
  s.onload = function() {
  this.parentNode.removeChild(this);
  };
  (document.head||document.documentElement).appendChild(s);
  </code></pre>
  
  <p>Method 2a:</p>
  
  <p>(Uses old Manifest.js)</p>
  
  <p>makeNormalLinks.js:</p>
  
  <pre><code>var actualCode = ['$(document).ready(function(){',
                    '$("a").each(function(){',
                    '$(this).removeAttr("onclick");',
                    '});',
                    '});'].join('\n');
  
  var script = document.createElement('script');
  script.textContent = actualCode;
  (document.head||document.documentElement).appendChild(script);
  script.parentNode.removeChild(script);
  </code></pre>
  
  <p>Unfortunately, neither method seems to work. I'm extremely grateful to those who commented and think we're getting close to an answer.</p>
  
  <hr>
  
  <p>Solution:</p>
  
  <p>Manifest.json:</p>
  
  <pre><code>{
  "manifest_version": 2,
  
  "name": "DHS Links",
  "description": "Stops the school's site from constantly opening new windows.",
  "version": "1.0",
  
  "browser_action": {
  "default_icon": "icon.png"
  },
  
  "content_scripts":[
    {
      "matches": ["*://www.darienps.org/dhs/*"],
      "js": ["makeNormalLinks.js"]
  
    }
   ]
  }
  </code></pre>
  
  <p>makeNormalLinks.js:</p>
  
  <pre><code>document.addEventListener("click", function(e) {
      e.stopPropagation();
  }, true);
  </code></pre>
  
  <p>Thanks you, Scott and all who commented!</p>