小编use*_*376的帖子

Chrome 扩展程序将 html 注入到特定的 div

我正在尝试为 chrome 制作一个扩展,将 html 代码注入特定页面上的特定 div。

这是我想注入一些代码的示例页面:http : //netdna.webdesignerdepot.com/uploads7/creating-a-modal-window-with-html5-and-css3/demo.html

到目前为止,我已经做到了:manifest.json:

{
"manifest_version":         2,
"content_scripts":          [ {
    "js":       [ "iframeInjector.js" ],
    "matches":  [   "http://netdna.webdesignerdepot.com/*/*/*"
    ]
} ],
"description":              "Inject html",
"name":                     "Inject html",
"version":                  "1",
"web_accessible_resources": ["test.html"]
}
Run Code Online (Sandbox Code Playgroud)

测试.html:

Test html code
Run Code Online (Sandbox Code Playgroud)

iframeInjector.js:

var iframe  = document.createElement ("iframe");
iframe.src  = chrome.extension.getURL ("test.html");
document.body.insertBefore (iframe, document.body.openModal);
Run Code Online (Sandbox Code Playgroud)

在示例页面上有一个名为“openModal”的 div,如何将我的 html 代码注入到该 div 中?

另一个问题:有没有办法将页面标题读取到变量并在我感染的 html 代码中使用该变量?

谢谢..

google-chrome google-chrome-extension content-script

5
推荐指数
1
解决办法
5404
查看次数