iframe里用jquery获取父页面body

iframe.html

<html>
<script src='jquerymin.js'>
</script>
<body id='1'>
    <div>it is a iframe</div>
</body>   
<script>
    $(document).ready(
        function()
        {
          
        var c = $(window.parent.document.body) //麻烦的方法: var c = $($(window).eq(0)[0].parent.document).find('body'); ,忘了可以用前面的方法了
           
        alert(c.html());
        }
    );
   
</script>
</html>





content.html

<html>
    <script src='jquerymin.js'>
</script>
<body id='fa'>
    <iframe src='iframe.html' width='100' height='100'></iframe>
    <br>
        <br>
            <br>
            <div id='mydiv'>content iframe</div>
</body>   
<script>
    function a()
    {
        alert(1);
    }
    alert($(document).text());
    </script>
</html>
原文地址:https://www.cnblogs.com/luluping/p/1440617.html