Iframe自适应问题解决方案
发布:apollo | 发布时间: 2009年6月26日 今天早上在关注搜索引擎的世界,有篇文章是那么说微软的Bing的,Bing搜索引擎的目的是让用户好用,也列举了很多他的优势,抱着尝试下的心理,果断的使用了搜索了下技术问题,呵呵,还真的被找到了,很直观很明了。
Iframe自适应这个问题应该不算是老问题了,只是以前一直都没有怎么去使用过,这里把代码直接贴出来给大家,从一个网友哪里转来的,希望对大家有所帮助。
<script language="javascript" type="text/javascript">
function iframeAutoFit() {
var ex;
try {
if (window != parent) {
var a = parent.document.getElementsByTagName("IFRAME");
for (var i = 0; i < a.length; i++) {
if (a[i].contentWindow == window) {
var h1 = 0, h2 = 0;
if (document.documentElement && document.documentElement.scrollHeight) {
h1 = document.documentElement.scrollHeight;
}
if (document.body) h2 = document.body.scrollHeight;
var h = Math.max(h1, h2);
if (document.all) { h += 4; }
if (window.opera) { h += 1; }
a[i].style.height = h + "px";
parent.document.getElementById("left_split").style.height = (h - 164) + "px";
}
}
}
}
catch (ex) { }
}
if (document.attachEvent) {
window.attachEvent("onload", iframeAutoFit);
window.attachEvent("onresize", iframeAutoFit);
}
else {
window.addEventListener('load', iframeAutoFit, false);
window.addEventListener('resize', iframeAutoFit, false);
}
</script>
- 相关文章:
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。





