iframe嵌套页面完整显示

  • A+
所属分类:前端

在嵌入页面不能全部展示的问题中,可以通过js改变iframe的高度。

HTML代码

<iframe src="#" name="i" id="urlIframe" width="100%" height="100%" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" onload="reinitIframe()"></iframe>

JS代码

function reinitIframe() {
var iframe = document.getElementById("urlIframe");
try
{
var bHeight = iframe.contentWindow.document.body.scrollHeight;
iframe.height = bHeight;
} catch (ex) { }
}

示例

<html>  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Colin-iframe Test</title>
</head>
<body>  
<iframe src="https://www.com" height="100%" width="100%" id="frame_full" frameborder="0" scrolling="auto"  οnlοad="this.style.height=document.body.clientHeight-50"></iframe>
</body>
</html>
weinxin
独角兽驿站
公众号

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: