我正在尝试对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"]
}
test.html:
Test html code
iframeInjector.js:
var iframe = document.createElement ("iframe");
iframe.src = chrome.extension.getURL ("test.html");
document.body.insertBefore (iframe, document.body.openModal);
在示例页面上有一个名为“ openModal”的div,我如何将html代码注入该div中?
另一个问题:有没有办法读取页面标题为变量并在我感染的html代码中使用该变量?
谢谢..
因此id="openModal"
,您要向其添加iframe的div ?
iframeInjector.js
var iframe = document.createElement ("iframe");
iframe.src = chrome.extension.getURL ("test.html");
var yourDIV = document.getElementById("openModal");
yourDIV.appendChild(iframe);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句