iframe 笔记
# 获取iframe
window对象
const
iframe.contentDocument || window.frames.iframeWrapper.document
1
2
2
# 模拟点击事件
function trigger(node, event){
if(document.all) {
node.click();
}else {
var e = document.createEvent("MouseEvents");
e.initEvent(event, true, true);
node.dispatchEvent(e);
}
}
document.getElementById("resource").addEventListener("click", function(e){
trigger(document.getElementById("target"), "click");
},false);
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
# iframe加载完成
<iframe id="ifra" name="ifra" width="100%" height="500" src="http://xxxxx">
</iframe>
const iframe = document.querySelector('#ifra')
if (iframe.attachEvent) {
iframe.attachEvent("onload", function() {
const iframeNode = window.frames["ifra"].document
self.getDom(iframeNode)
});
} else {
iframe.onload = function() {
const iframeNode = window.frames["ifra"].document
self.getDom(iframeNode)
};
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
上次更新: 2022/06/05, 20:31:36