js获取iframe的window对象(包括iframe中不存在name和id的情况)

2021-07-12 21:04

阅读:399

标签:pos   ntb   方法   tps   post   直接   nbsp   class   包括   

js获取iframe中的元素以及在iframe中获取父级的元素(包括iframe中不存在name和id的情况)

 

 

 

 

第一种情况:iframe中不存在name和id的方法:(通过contentWindow获取)

 

iframe src="about:_blank" id="iframeId">iframe>
script>
document.getElementById(iframeId).contentWindow
script>

第二种iframe里面有name属性

iframe src="about:_blank" name="iframeId">iframe>
script>
// 得到的直接就是window对象
window.frames["iframeId"]
script>

 

js获取iframe的window对象(包括iframe中不存在name和id的情况)

标签:pos   ntb   方法   tps   post   直接   nbsp   class   包括   

原文地址:https://www.cnblogs.com/yeminglong/p/15001732.html


评论


亲,登录后才可以留言!