您的位置:首页 > 其它

跨域实现IFRAME自适应高度

2011-12-13 00:06 351 查看
<html>
<head>
</head>
<body>
<script>
document.domain="sina.com";
function adjustIframe(id)
{
var iframe = document.getElementById(id)
var idoc = iframe.contentWindow && iframe.contentWindow.document || iframe.contentDocument;
var callback = function () {
var iheight = Math.max(idoc.body.scrollHeight, idoc.documentElement.scrollHeight); //取得其高
iframe.style.height = iheight + "px";
}
if (iframe.attachEvent) {
iframe.attachEvent("onload", callback);
} else {
iframe.onload = callback
}
}

var ifm=document.createElement("iframe");
ifm.src="http://test.sina.com/2.htm";
ifm.width=1000;
ifm.id="ok1";
ifm.domain="sina.com";
document.body.appendChild(ifm);
adjustIframe("ok1");

</script>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: