[英]HTML shows as plain text when inserted into webpage
我正在开发chrome扩展程序,希望将其插入iframe到Google主页中,但是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>";
感谢您的任何帮助。
innerText检索内容并将其设置为纯文本。 如果要设置HTML,请使用innerHTML。
var div=document.createElement("div");
document.getElementById("searchform").appendChild(div);
div.innerHTML="<iframe src='https://www.google.com.au/'>ERROR</iframe>";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.