Search code examples
javascriptgoogle-chrome-extensionchrome-dev-editor

Script tags don't work in Chrome Dev Editor


I'm using the Chrome App "Chrome Dev Editor" to make an Extension, but for some reason the script tags (which are in body tags) don't seem to work. I have tried to take the code and put it in codepen.io (an online HTML/CSS/JS editor and it seems to work fine there.

Here is the code:

<div id = "thingy"></div>
<script>
  document.getElementById("thingy").innerHTML = "Yo";
</script>

Any help is greatly appreciated, and sorry for my lack of knowledge on this topic. Thanks!


Solution

  • Chrome doesn't allow javascript in extensions like that. The code has to be in a separate .js file for it to work as an extension.

    Just swap your code for this:

    <script src="otherfile.js"></script>
    

    Then put the javascript in otherfile.js