Chrome extension changing popup.html text

强颜欢笑 提交于 2019-12-24 04:27:14

问题


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"
  }
}

回答1:


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>


来源:https://stackoverflow.com/questions/19007860/chrome-extension-changing-popup-html-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!