Skip to content

Commit fc9bdfa

Browse files
committed
DOMContentLoaded中加载dom、load中push ad
1 parent 54609f1 commit fc9bdfa

File tree

1 file changed

+46
-21
lines changed

1 file changed

+46
-21
lines changed

Writerside/cfg/head-script.html

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,50 @@
1919

2020
<script>
2121
/*横向广告*/
22-
window.onload=function () {
23-
try {
24-
const elements = document.getElementsByTagName('article');
25-
if (elements && elements.length > 0) {
26-
const article = elements[0];
27-
const insDiv = document.createElement('div');
28-
insDiv.setAttribute('class', 'ins_div');
29-
const ins = document.createElement('ins');
30-
ins.setAttribute('class', 'adsbygoogle adsbygoogle_inline_ins');
31-
/*ins.setAttribute('style', 'display:block');*/
32-
ins.style.display = 'block';
33-
ins.setAttribute('data-ad-client', 'ca-pub-4062299174917944');
34-
ins.setAttribute('data-ad-slot', 'auto');
35-
ins.setAttribute('data-full-width-responsive', 'true');
36-
insDiv.appendChild(ins);
37-
article.appendChild(insDiv);
38-
(adsbygoogle = window.adsbygoogle || []).push({});
39-
console.log('adsbygoogle pushed.');
40-
}
41-
} catch(e) {console.log(e);}
42-
};
22+
document.addEventListener("DOMContentLoaded", (event) => {
23+
try {
24+
const elements = document.getElementsByTagName('article');
25+
if (elements && elements.length > 0) {
26+
const article = elements[0];
27+
const insDiv = document.createElement('div');
28+
insDiv.setAttribute('class', 'ins_div');
29+
const ins = document.createElement('ins');
30+
ins.setAttribute('class', 'adsbygoogle adsbygoogle_inline_ins');
31+
/*ins.setAttribute('style', 'display:block');*/
32+
ins.style.display = 'block';
33+
ins.setAttribute('data-ad-client', 'ca-pub-4062299174917944');
34+
ins.setAttribute('data-ad-slot', 'auto');
35+
ins.setAttribute('data-full-width-responsive', 'true');
36+
insDiv.appendChild(ins);
37+
article.appendChild(insDiv);
38+
// in loaded
39+
window.addEventListener('load',function(){
40+
(adsbygoogle = window.adsbygoogle || []).push({});
41+
console.log('adsbygoogle pushed.');
42+
});
43+
44+
}
45+
} catch(e) {console.log(e);}
46+
});
47+
//window.onload=function () {
48+
//try {
49+
//const elements = document.getElementsByTagName('article');
50+
//if (elements && elements.length > 0) {
51+
// const article = elements[0];
52+
// const insDiv = document.createElement('div');
53+
// insDiv.setAttribute('class', 'ins_div');
54+
// const ins = document.createElement('ins');
55+
// ins.setAttribute('class', 'adsbygoogle adsbygoogle_inline_ins');
56+
// /*ins.setAttribute('style', 'display:block');*/
57+
// ins.style.display = 'block';
58+
// ins.setAttribute('data-ad-client', 'ca-pub-4062299174917944');
59+
// ins.setAttribute('data-ad-slot', 'auto');
60+
// ins.setAttribute('data-full-width-responsive', 'true');
61+
// insDiv.appendChild(ins);
62+
// article.appendChild(insDiv);
63+
// (adsbygoogle = window.adsbygoogle || []).push({});
64+
// console.log('adsbygoogle pushed.');
65+
//}
66+
//} catch(e) {console.log(e);}
67+
//};
4368
</script>

0 commit comments

Comments
 (0)