我正在开发Chrome扩展程序,我希望它在Google主页中插入iframe,但html只显示为纯文本。为什么会这样?
这是我目前的代码:
的manifest.json
{
"manifest_version": 2,
"name": "Google",
"version": "1.0",
"description": "Google iframe",
"icons": {
"48": "img/rsz_apple-touch-icon-144x144.png",
"16": "img/favicon-16x16.png",
"128": "img/rsz_1apple-touch-icon-144x144.png"
},
"content_scripts": [{
"matches": ["https://www.google.com.au/"],
"js": ["content-script.js"]
}],
"browser_action": {
"default_icon": "img/favicon-16x16.png",
"default_title": "Press the button to see more actions",
"default_popup": "popup.html"
},
"background": {
"page": "background.html"
},
"permissions": [
"activeTab"
]
}
内容-的script.js
var div=document.createElement("div");
document.getElementById("searchform").appendChild(div);
div.innerText="<iframe src='https://www.google.com.au/'>ERROR</iframe>";
感谢您的帮助。
答案 0 :(得分:2)
innerText检索内容并将其设置为纯文本。如果要设置HTML,请使用innerHTML。
var div=document.createElement("div");
document.getElementById("searchform").appendChild(div);
div.innerHTML="<iframe src='https://www.google.com.au/'>ERROR</iframe>";