父层:第一个是方法申明 第二个是接收子层过来的数据
<script type="text/javascript">
$("#main").load(function(){ window.frames[0].postMessage("getMessage","*"); window.addEventListener("message",function(e){ var height1=e.data; $("#main").css("height",height1); }) }) </script> <script type="text/javascript"> window.frames[0].postMessage("getMessage2","*"); window.addEventListener("message",function(e){ var height1=e.data; $("#main").css("height",height1); }) </script>
子层:
<script type="text/javascript">
window.addEventListener('message', function(e) { if(e.source != window.parent) return; var height = $("body").height(); window.parent.postMessage(height, '*'); }, false); </script>最终让父层根据子层的高度自适应