我正在动态创建iframe:
function iFrame(parentElement)
{
var iframe = document.createElement("iframe");
if (parentElement == null)
{
parentElement = document.body;
}
parentElement.appendChild(iframe);
iframe.doc = null;
if (iframe.contentDocument)
{
iframe.doc = iframe.contentDocument; // Opera, Firefox
}
else if(iframe.contentWindow)
{
iframe.doc = iframe.contentWindow.document; // Internet Explorer
}
else if(iframe.document)
{
iframe.doc = iframe.document;
}
if(iframe.doc == null)
{
throw "Application failed to dynamically create an iframe content";
}
iframe.doc.open();
iframe.doc.close();
return iframe;
}
... with document.onload:
function onPageLoad()
{
var iframeDiv = document.getElementById("iframeDiv");
var iframe = new iFrame(iframeDiv);
}
如何将此iframe拉伸到其父div并关闭使用JavaScript滚动?
答案 0 :(得分:3)
您可以通过设置:
关闭iframe中的滚动iframe.style.overflow = "hidden"
如果父div具有已定义的高度和宽度,则可以将iframe设置为具有100%的高度和宽度:
iframe.style.width = iframe.style.height = "100%";