Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension changing popup.html text

I'm a complete novice, i want to take a text from a "p" tag and put it in another "p" tag so when i click on my extension i see the two texts being displayed. What i'm doing wrong? and how can i avoid similar mistakes in the future?

popup.html:

<!DOCTYPE html>
<html>
      <head>
        <script type="text/javascript" scr= "popup.js"></script>
      </head>
      <body>            
        <p id="firstText">this is the text to be repeated</p> 
        <p id= "secondText"></p>        
     </body>   
</html>

popup.js:

document.addEventListener('DOMContentLoaded', function () {

 var test= document.getElementById("firstText").innerHTML;
 document.getElementById("secondText").innerHTML=test;

});

manifest.json:

{
  "manifest_version": 2,
  "name": "test",
  "description": "useless",
  "version": "1.0",
   "background": {
      "scripts": [ "popup.js"],
      "persistent": false
   }, 
  "content_scripts": [
    {
      "matches": ["http://*/*"],  
      "js": ["popup.js"]
    }
    ], 
    "permissions": [
    "activeTab","tabs", "http://*/*"
  ],
  "browser_action": {
    "default_popup": "popup.html"
  }
}
like image 714
Apastrix Avatar asked Mar 22 '23 07:03

Apastrix


1 Answers

Use this HTML for popup: you are having typo mistake src

<!DOCTYPE html>
<html>
      <head>
        <script type="text/javascript" src= "popup.js"></script>
      </head>
      <body>            
        <p id="firstText">this is the text to be repeated</p> 
        <p id= "secondText"></p>        
     </body>   
</html>
like image 182
Raghvendra Parashar Avatar answered Apr 01 '23 03:04

Raghvendra Parashar