Posted on 2010-05-04 11:00
leekiang 阅读(406)
评论(0) 编辑 收藏 所属分类:
web开发
192.168.108.25/AppA的a.jsp里有一个iframe为b.jsp,a和b跨域,如何让这个iframe自适应高度?
a.jsp
<iframe src="http://192.168.2.97/AppB/b.jsp" id="b_iframe" scrolling="no" frameborder="0"></iframe>
b.jsp
<iframe id='c_iframe' height='0' width='0' src='http://192.168.108.25/AppA/c.jsp' style='display:none' ></iframe>
<script>
var b_height = Math.max(document.body.scrollHeight,document.body.clientHeight);
var c_iframe = document.getElementById('c_iframe');
c_iframe.src = c_iframe.src+'#'+b_height;
</script>
c.jsp
<script>
var hash_url = window.location.hash;
var hash_height = hash_url.split('#')[1]+'px';
var b_iframe = window.parent.parent.document.getElementById('b_iframe');
b_iframe.style.height = hash_height;
</script>