背景介绍:
www.aaaa.com有一个a.jsp,其中在a.jsp中内嵌一个iframe,这个iframe的id="frame",src="http://www.bbb.com/b.php"
问题:
解决办法:
示例代码:
a.jsp:
<iframe id="frame1" name="frame1" frameborder="0" width="100%" onload="" scrolling="no" src="http://www.bbb.com/b.php"></iframe>
b.php:
<script>
$(function(){
var frame = document.getElementById("frame");
frame.src = "http://www.aaa.com/c.jsp" + "#" + $("body").height();
});
</script>
<iframe id="frame" width="100%" src="" style="display:none"></iframe>
c.jsp:
<script type="text/javascript">
//得到a.jsp中的iframe
var a_iframe = parent.parent.document.getElementById("frame1");
//这个值通过b.php中的js函数改变。包括height属性
var hash_url = window.location.hash;
//得到c.jsp传递过来的height属性
var hash_height = hash_url.split("#")[1];
var height = hash_height;
//调整iframe的height,达到自适应
a_iframe.height = height + "px";
</script>