Posted on 2010-05-04 11:00
leekiang 閱讀(411)
評論(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>