开发者

How to add an iframe to the content / DOM using a firefox extension?

开发者 https://www.devze.com 2023-04-01 04:48 出处:网络
I\'m trying to add an iframe to the content / DOM of a webpage using a firefox extension. Here is my code:

I'm trying to add an iframe to the content / DOM of a webpage using a firefox extension.

Here is my code:

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);
}

It's a modified version from this answer: Execute JS from Firefox extension

I replaced this line:

// Inject it into the top-level element of the document
document.documentElement.appendChild(script);

With this line:

window.content.appendChild(iframe);

开发者_C百科Because it was inserting the iframe into the chrome of the browser and not into the content area DOM. What is the right command to insert it into the page? (My command is not working)


And the correct answers goes to... me!

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;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消