page.vue
1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<template>
<LayoutApp :title="title">
<iframe ref="iframe" :onload="onload()" :src="url" class="page"></iframe>
</LayoutApp>
</template>
<script>
export default {
name: "IframePage",
data() {
return {
show: false,
title: '',
// url: 'https://www.baidu.com',
url: 'http://activity.yoho.cn/feature/6823.html?title=一键领取680元神劵&nodownload=1'
};
},
mounted() {
this.show = true;
},
methods: {
onload() {
setTimeout(() => {
this.loadPage();
}, 100)
},
loadPage() {
console.log('onload');
console.log({...this.$refs});
if (!this.$refs.iframe) {
return;
}
const elemIfram = this.$refs.iframe;
const contentWindow = elemIfram.contentWindow;
// const iframeDocument = contentWindow.document;
console.log(contentWindow)
if (contentWindow.MutationObserver || contentWindow.webkitMutationObserver) {
console.log(11)
let observer;
// chrome
let callback = function(mutations) {
mutations.forEach(function(mutation) {
console.log(mutation.oldValue, mutation.target.src, mutation.target);
});
};
if (contentWindow.MutationObserver) {
observer = new MutationObserver(callback);
} else {
observer = new webkitMutationObserver(callback);
}
observer.observe(elemIfram, {
attributes: true,
attributeOldValue: true
});
} else if (elemIfram.addEventListener) {
console.log(22)
// Firefox, Opera and Safari
elemIfram.addEventListener("DOMAttrModified", function(event){
console.log(event.prevValue,event.newValue,event.target);
}, false);
}
// console.log(iframeDocument.getElementsByTagName('a'));
}
}
};
</script>
<style lang="scss" scoped>
.page {
width: 100%;
height: 100%;
position: absolute;
top: 0;
bottom: 0;
}
</style>