<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>
本文转自博客园张占岭(仓储大叔)的博客,原文链接:跨域实现IFRAME自适应高度,如需转载请自行联系原博主。