0

So I started making a chrome extension, but bumped into a problem rather fast, when I press a button (only element in the popup.html file), it does not run a script that it should, while it does when I run the html file as a webpage.

<!DOCTYPE html>
<html>
  <head>
    <script>
      function mainbuttonpressed() {
        document.getElementById("mainbutton").innerHTML = "B"
        console.log("pressed1")
        alert("You pressed the button!")
        console.log("pressed2")
      }
    </script>
    <link rel="stylesheet" href="button.css">
  </head>
  <body>
    <button id="mainbutton" type="button" onclick="mainbuttonpressed()">A</button>
  </body>
</html>


How does it come that it works when I use it as webpage, but the exact same html doesn't react when used as the default_popup in a chrome extension?

VioPaige
  • 37
  • 1
  • 5
  • Try adding an event listener in the script, `document.getElementById("main-button").addEventListener("click", mainbuttonpressed)` – AHMED SAJJAD Jul 29 '21 at 10:40
  • isn't this an entire different way of detecting the click? I'm wondering why mine doesn't work, not how else I can do it. – VioPaige Jul 29 '21 at 10:45

0 Answers0