Chrome扩展程序更改popup.html文本 [英] Chrome extension changing popup.html text
本文介绍了Chrome扩展程序更改popup.html文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个完整的新手,我想从"p"标签中提取文本并将其放在另一个"p"标签中,因此当我单击扩展名时,我看到正在显示的两个文本. 我做错了什么?以及将来如何避免类似的错误?
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:
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.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"
}
}
推荐答案
使用此HTML弹出窗口:您有错字错误 src
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>
这篇关于Chrome扩展程序更改popup.html文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文