<a target="test" href="...">链接</a>
<iframe id="test" name="test" src="init.html"></iframe>iframe加载时的自适应高度我已经解决了
但是,我希望在我点击 "链接" 更换页面的时候iframe的高度是新页面的高度
不知道该怎么弄。
哪位大虾指点下.
全部家当都拿出来了
<iframe id="test" name="test" src="init.html"></iframe>iframe加载时的自适应高度我已经解决了
但是,我希望在我点击 "链接" 更换页面的时候iframe的高度是新页面的高度
不知道该怎么弄。
哪位大虾指点下.
全部家当都拿出来了
//会自动根据加载页面调整高度
//iframeurl是iframe链接页面地址
<iframe id="sqiframe" name="sqiframe" src="<%=iframeurl%>" frameborder="0" width="100%" onload="AdjustHeight();"></iframe>
<script language="javascript" type="text/javascript">
function AdjustHeight()
{
if(sqiframe.document.body.scrollHeight+40 < 485)
{
document.getElementById("sqiframe").height = 485;//如果加载页面高度没485就调整为485
}
else
{
document.getElementById("sqiframe").height=sqiframe.document.body.scrollHeight+40
}
}
</script>楼主看看如何?
<iframe id="test" name="test" src="init.html" onload="ResizeFrame(this.id)"></iframe>
<script>
//你的连接没有跨域时可以使用下面代码
var IE=document.all?true:false;
function ResizeFrame(id)
{
var frame=document.getElementById(id);
var doc=IE?frames[id].document:document.getElementById(id).contentWindow.document;
frame.style.height=doc.body.scrollHeight+"px";
frame.style.width=doc.body.scrollWidth+"px";
}
</script>
document.getElementById("test") = test.document.body.clientHeight