父页面有个ID为mainfrm、name为Iframe1的iframe,iframe连接b.html,该页面有个函数test

在父页面调用b.html的test方法为:

$("#mainfrm")[0].contentWindow.test();

或者

this.frames["Iframe1"].doQuery();

在当前弹出的子页面中打开另一个打开页面中的函数,例如在弹出的edit.html页面中调用dataList.html页面中的函数test

parent.document.frames["Iframe1"][0].test();

 

////////////////////////////////////////////////////////////////////////////////////

第一、在iframe中查找父页面元素的方法:

$('#id', window.parent.document)

第二、在父页面中获取iframe中的元素方法:

$(this).contents().find("#suggestBox")

第三、在iframe中调用父页面中定义的方法和变量:

parent.method

parent.value

 

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>
View Code

 

 

posted on 2014-07-10 10:41  Haydy  阅读(7133)  评论(0编辑  收藏  举报