跨域实现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>
<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>
相关文章推荐
- CSS完美实现iframe高度自适应(支持跨域)
- 完美实现跨域Iframe高度自适应【Iframe跨域高度自适应解决方案】
- IFrame跨域高度自适应实现代码
- iframe自适应内层页面高度,可响应页面中折叠点击事件,以及实现跨域的问题解决方案
- 跨域实现IFRAME自适应高度~续(终级)
- 完美实现跨域Iframe高度自适应【Iframe跨域高度自适应解决方案】
- 完美实现跨域Iframe高度自适应
- 完美实现跨域Iframe高度自适应【Iframe跨域高度自适应解决方案】
- 实现跨域Iframe高度自适应调整
- 完美实现跨域Iframe高度自适应【Iframe跨域高度自适应解决方案】
- 跨域实现IFRAME自适应高度
- IFrame跨域高度自适应实现代码
- 2级域名实现iframe域名跨域自适应高度
- 利用剪切板实现IFrame跨域自适应高度
- 跨域访问Iframe自适应高度(兼容Firfox,IE)
- Iframe自适应高度 同域/跨域 mvc3
- 实现 iframe 的自适应高度
- jquery实现iframe自适应高度代码
- 如何设置iframe高度自适应在跨域情况下的可用方法
- 实现iFrame自适应高度,原来很简单!