iframe 子页面获取父页面的元素并且控制样式

时间:2021-11-11 21:07:13

父页面的代码

                      <div id="div5" style="position:relative;height:500px;">
                       <iframe scrolling="auto" frameborder="0"  id="content" name="content" src ="./cpcia_gonggao.jsp"
                        bordor="0" style="width:800px;height:500px;">
                       </iframe>
                       </div>  

 

子页面的JS代码

 

<script>
$(function(){
    var p_window = window.top;
    alert($(p_window).height());
    var p_demo = window.top.document.getElementById('content');
    var val=window.top.document.getElementById('div5');
    alert($(p_demo).height()); 
    p_demo.style.height="1300px";
    val.style.height="1300px";
})
</script>