且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用Javascript将Iframe插入Div中 - 用于Greasemonkey

更新时间:2022-04-17 07:14:47

1-你可以使用 element.appendChild

makediv.appendChild(makeIframe);

2-或者将iframe作为html附加到div中,像这样,

2- Or append iframe as html into div like this,

makediv.innerHTML = '<iframe src="http://aol.com" style="border: 0pt none ;'+ 
                    'left: -453px; top: -70px; position: absolute;'+ 
                    'width: 1440px;'+ 
                    'height: 775px;" scrolling="no"></iframe>';

比将makediv插入到你想要的地方,

than insert makediv to where you want,

var getRef = document.getElementById("div-id-to-insert-element-before");
var parentDiv = getRef.parentNode;
parentDiv.insertBefore(makediv, getRef);

更新:

您无法使用 setAttribute 功能设置样式,

You cannot set style with setAttribute function,

var makeIframe = document.createElement("iframe");
makeIframe.setAttribute("src", "http://aol.com");
makeIframe.setAttribute("scrolling", "no");
makeIframe.style.border = "none";
makeIframe.style.left =  "-453px";
makeIframe.style.top = "-70px";
makeIframe.style.position = "absolute";
makeIframe.style.width = "1440px";
makeIframe.style.height = "775px";

var makediv = document.createElement("div");
makediv.style.height = "43px";
makediv.style.width = "564px";
makediv.style.position = "relative";
makediv.style.overflow = "hidden";