无法在Javascript小书签中正确定位iFrame

时间:2019-05-22 01:21:30

标签: javascript html css iframe position

我一直在做一个嵌入了iFrame的Javascript小书签,我无法正确对齐iFrame

我尝试了每种对齐方式和不同的定位方式,但是没有运气

var AppendedFrame = document.createElement("iFrame"); 
    AppendedFrame.src="https://www.google.com";
    AppendedFrame.setAttribute("position", "absolute");
    AppendedFrame.setAttribute("width", "400"); 
    AppendedFrame.setAttribute("height", "225"); 
    AppendedFrame.setAttribute("top", "2px");
    AppendedFrame.setAttribute("right", "3px"); 
    AppendedFrame.setAttribute("z-index", "2147483648"); 
document.body.appendChild(AppendedFrame);

我期望的输出是使iFrame出现在右上角并停留,但是iFrame停留在它的默认位置。

编辑:顺便说一下,Google只是一个例子,完成后我将使用其他网站。

1 个答案:

答案 0 :(得分:0)

var AppendedFrame = document.createElement("iFrame"); 
AppendedFrame.src="https://www.baid.com";
AppendedFrame.setAttribute("style",'"position":"absolute";"width":"400";"height":"225";"top":"2px";"right":"3px";"z-index":"2147483648"');
document.body.appendChild(AppendedFrame);