1

クロム拡張機能を開発していて、iframeをGoogleホームページに挿入したいのですが、htmlはプレーンテキストとして表示されます。なぜこれが起こるのですか?ここでウェブページに挿入すると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>"; 

はそれを示しものです: screenshot

ありがとうございました。

答えて

1

innerTextはコンテンツをプレーンテキストとして取得して設定します。 HTMLを設定する場合は、innerHTMLを使用してください。

var div=document.createElement("div"); 
document.getElementById("searchform").appendChild(div); 
div.innerHTML="<iframe src='https://www.google.com.au/'>ERROR</iframe>"; 
関連する問題