![](/img/trans.png)
[英]How do i alter the content of an iframe in the dom using firefox extension code?
[英]How to add an iframe to the content / DOM using a firefox extension?
我正在嘗試使用Firefox擴展將iframe添加到網頁的內容/ DOM。
這是我的代碼:
const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
function addIframe(src) {
// Create the script node
let iframe = document.createElementNS(XUL, "iframe");
iframe.setAttribute("src", src);
window.content.appendChild(iframe);
}
這是此答案的修改版本: 從Firefox擴展中執行JS
我替換了這一行:
// Inject it into the top-level element of the document
document.documentElement.appendChild(script);
用這行:
window.content.appendChild(iframe);
因為它是將iframe插入瀏覽器的鑲邊中,而不是內容區域DOM中。 將其插入頁面的正確命令是什么? (我的命令不起作用)
正確的答案是……我!
const XUL = Namespace("xul", "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
function addIframe(src) {
// Create the script node
let iframe = document.createElementNS(XUL, "iframe");
iframe.setAttribute("src", src);
window._content.document.body.appendChild(iframe);
return;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.