[英]iFrame and matching sidebar div height
所以我有一个html页面。 我有一个 iframe,它会在加载内容时调整大小,但我有一个侧边栏(div),我需要将高度设置为等于新的 iframe 高度。 我的 iframe 调整大小的 javascript 是
function setIframeHeight( iframeId ) /** IMPORTANT: All framed documents *must* have a DOCTYPE applied **/
{
var ifDoc, ifRef = document.getElementById( iframeId );
try
{
ifDoc = ifRef.contentWindow.document.documentElement;
}
catch( e )
{
try
{
ifDoc = ifRef.contentDocument.documentElement;
}
catch(ee)
{
}
}
if( ifDoc )
{
ifRef.height = 1;
ifRef.height = ifDoc.scrollHeight;
/* For width resize, enable below. */
// ifRef.width = 1;
// ifRef.width = ifDoc.scrollWidth;
}
}
实际上代码不是我的,感谢 Logic Ali 。
您将需要有一个像这样的 onResize 处理程序。
http://www.w3schools.com/jsref/event_onresize.asp
window.onresize=function(){
setIframeHeight( iframeId )
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.