0

I am trying to make a Chrome extension. And I can't change the text in div. Can you help me please? I can't find what's wrong here.

manifest.json:

{
      "name": "Test",
      "version": "0.0.1",
      "description": "Test app",
      "permissions": [ "background", "tts", "storage" ],

      "background": { "scripts": ["my.js"] },

      "browser_action": {
        "default_popup": "my.html"
      },

      "manifest_version": 2
    }

my.js:

function StartUp(){
    var data ="dater";
    document.getElementById("page").innerHTML = data;
}

my.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test app</title>
    <script src="my.js"></script>
  </head>
  <body>
    <div id="page" onclick="StartUp()">
hello
    </div>
  </body>
</html>
Jerey
  • 19
  • 4

1 Answers1

0

I rebuild your code and all OK:

my.js:

function StartUp(ev){
    var data ="dater";
    ev.target.textContent = data;
}

document.addEventListener('DOMContentLoaded', () => {

  let page = document.getElementById('page');
  page.addEventListener('click',StartUp)

})

my.html

<!doctype html>
<html>
  <head>
      <script src="my.js"></script>
  </head>
  <body>
    <div id="page">
       hello
     </div>
  </body>
</html>
  • @Jerey,show your errors in chrome://extensions/ in your app. – Сергей Петрашко Nov 26 '17 at 10:43
  • Yea it works, but I am getting the error message: "Uncaught TypeError: Cannot read property 'addEventListener' of null at HTMLDocument. (my.js:7)". I've changed only my.js and now the code is like: [code] function StartUp(e){ var data ="dater"; document.getElementById("page").innerHTML = data; } document.addEventListener('DOMContentLoaded', function () { document.querySelector('div').addEventListener('click', StartUp); }); [/code] – Jerey Nov 26 '17 at 10:50
  • Well don't put the code in comments. Edit the question. – JJJ Nov 26 '17 at 10:58