最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Chrome extension changing popup.html text - Stack Overflow

programmeradmin4浏览0评论

I'm a plete 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"
  }
}

I'm a plete 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"
  }
}
Share Improve this question asked Sep 25, 2013 at 14:35 ApastrixApastrix 1142 silver badges12 bronze badges 2
  • 6 If this is an exact copy / paste, you have a typo in <script type="text/javascript" scr= "popup.js"></script>. It should read src instead of scr. – Métoule Commented Sep 25, 2013 at 15:03
  • @ChrisP I'm so embarrassed, thank you very much for your help! – Apastrix Commented Sep 26, 2013 at 10:20
Add a ment  | 

1 Answer 1

Reset to default 7

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>
发布评论

评论列表(0)

  1. 暂无评论