近期做一些非单页应用的管理后台页面中,iframe父子页面调用难以避免。
jquery使用,现在总结如下:
1.父调用iframe中的元素(一定要iframe是load状态):
$('#iframe').load(function() {
$("#iframe").contents().find('.footer').html('88888')
//或者如下
$("#iframe")[0].contentWindow.$('.footer').html('000000');
// 或者如下
$($('#iframe').prop('contentWindow').document).find(".footer").html('111111');
//调用子页面方法
$("#iframe")[0].contentWindow.childFn();
});
2.子页面调用父页面的方法
//调用父方法
window.parent.parentFn({name:'abc', age:555, list:[1,3,4]});
//查找父元素
$(window.parent.document).find('#ele')