javascript--iframe的JS方法,用法!contentWindow 、parent、top、onload
2018-03-23 15:28
489 查看
还是先感谢“妙味课堂”出的这期教学视频!一、在使用iframe的页面,要操作这个iframe里面的DOM元素可以用:contentWindow、contentDocument(测试的时候chrom浏览器,要在服务器环境下) 1.先获取iframe里面的window对象,再通过这个对象,获取到里面的DOM元素例子:
var ifr = document.getElementById("iframe"); ifr.contentWindow.document.getElementById("XXXXX") <iframe src="a.html" id=""></iframe>ifr.contentWindow 这里,返回的是iframe的window对象,所以后面可以接着调用document方法,再接着调用getElementByTagName。那么就可以对iframe里面的元素进行操作了。 二、在iframe本页面,要操作这个iframe的父页面的DOM元素(即嵌套这个iframe的页面)可以用:window.parent、window.top(这里的TOP是获取的顶层,即有多层嵌套iframe的时候使用)
var ifr = document.getElementByTagName("iframe"); ifr.parent.document.getElementById("XXXXX") <iframe src="a.html" id=""></iframe>三、onload事件非IE下用法
ifr.onload = function(){ //SOMETHING }IE下,需要绑定
ifr.attachEvent("onload",function(){ //something })
相关文章推荐
- 【javascript】javascript中iframe的JS方法,用法!contentWindow 、parent、top、onload(热推)
- javascript--iframe的JS方法,用法!contentWindow 、parent、top、onload
- javascript--iframe的JS方法,用法!contentWindow 、parent、top、onload
- javascript--iframe的JS方法,用法!contentWindow 、parent、top、onload
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别(跳出iframe方法)
- javascript--iframe的JS方法,用法!contentWindow 、paren...
- JS iframe父子页面元素调用方法 window parent top 解释
- 关于js iframe 中"window(parent)(top).location.href"的用法
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
- iframe的跳转方法_javascript_js
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的使用方法
- 关于js中"window.location.href"、"location.href"、"parent.location.href"、"top.location.href"的用法
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法与区别
- 通过<frameset>和<iframe>看JavaScript中window对象parent、self、top的区别
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
- 关于js中window.location.href,location.href,parent.location.href,top.location.href的用法
- javascript的top,parent,opener,iframe