js、jquery操作父子iframe

以下方法在火狐、谷歌浏览器中测试通过

1.js获取子iframe中的元素

document.getElementById('iframe的id').contentWindow.document.getElementById('childDiv')
window.frames["iframe的id"].contentDocument.getElementById('childDiv');
//注意:上面的 .contentDocument 相当于 .contentWindow.document !
//获取了子页面的document对象后就可以采用js的方法获取、操作子页面的元素了
2.jque获取子iframe中的元素

$(window.frames["iframe的id"].contentWindow.document).find("#childDiv")
$("#main_frame").contents().find("#childDiv")
3.页面刷新子iframe内容

document.getElementById('iframe的id').src=document.getElementById('iframe的id').src;
4.页面调用子iframe的方法

$("iframe的id")[0].contentWindow.child();
//child()表示子iframe中的方法

5.子iframe获取父页面元素

//通过js获取
window.parent.document.getElementById("parentDiv");
//通过jquery获取
$('#parentDiv', parent.document);
6.子iframe刷新父页面

parent.location.reload();
7.子iframe调用父页面方法

window.parent.parent();
//parent指父页面的方法
8.子页面刷新自己

history.go(0)             
location.reload()         
location=location         
location.assign(location) 
location.replace(location)


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值