<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>
跨域实现IFRAME自适应高度
最新推荐文章于 2023-09-13 18:53:33 发布