gpt4 book ai didi

google-chrome - Chrome 扩展将 html 注入(inject)特定的 div

转载 作者:行者123 更新时间:2023-12-04 16:52:30 45 4
gpt4 key购买 nike

我试图为 chrome 做一个扩展,将 html 代码注入(inject)特定页面上的特定 div。

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

到目前为止,我已经做到了:
list .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"]
}

测试.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 代码注入(inject)到该 div 中?

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

谢谢..

最佳答案

所以有一个带有 id="openModal" 的 div要将 iframe 附加到哪个?

iframeInjector.js

var iframe  = document.createElement ("iframe");
iframe.src = chrome.extension.getURL ("test.html");
var yourDIV = document.getElementById("openModal");
yourDIV.appendChild(iframe);

关于google-chrome - Chrome 扩展将 html 注入(inject)特定的 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23882666/

45 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com