获取 Iframe内的元素对象

//这一篇是Javascript,不是Jquery

1,实现javascript重载iframe页面,兼容各浏览器的方法

document.getElementById(FrameID).contentWindow.location.reload(true);
2,其次是获取iframe内的元素并应用

iframe.contentWindow.document.getElementById(id).style.display="block";
3,iframe页面调用父级页面中的函数

parent.dofunction();

关键字:contentWindow与parent

contentWindow 实例

iframe = document.getElementById("frame");
iframe.contentWindow.location = "http://mozilla.org";
iframe.contentWindow.history.back();
说明 http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html

先整理这些,备录,继续完善。转自:http://www.liuhui.info/article16.html

 

获取 Iframe内的元素对象

test1.html //转自:http://fkshl.iteye.com/blog/715632
<html>
<head>
<script>
function t(){
var dd = document.all('test2').contentWindow.document;
dd.getElementById('my').style.display='none';

}
function getImage(paht)
{
var dd = document.all('test2').contentWindow.document;
dd.getElementById('covertImage').src=paht;
}
</script>
</head>
<body >
<input type="button" value="test" onClick="t();"/>
<input type="button" value="image1" onClick="getImage('1.jpg')"/>
<input type="button" value="image2" onClick="getImage('2.jpg')"/>
<input type="button" value="image3" onClick="getImage('3.jpg')"/>
<input type="button" value="image4" onClick="getImage('4.jpg')"/>
<iframe id="test2" name="test2" src="test2.html" frameborder="0" ></iframe>
</body>
</html>
test2.html
<html>
<head>
</head>
<body>
   
    <div id="my" name="my">
       测试一下,父窗体可以把我隐藏掉!!!!!!!!
   </div>
   <img src="" id="covertImage"/>
</body>
</html>

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值