网络编程
位置:首页>> 网络编程>> JavaScript>> google广告之另类js调用实现代码

google广告之另类js调用实现代码

作者:mdxy-dxy  发布时间:2024-05-11 09:44:21 

标签:js,google广告

今天发现一个google广告的另类调用方法


function addGoogel (content, obj) {
addScript('//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js', function () {
 var ins = document.createElement('ins')
 ins.setAttribute('class', 'adsbygoogle')
 ins.setAttribute('data-ad-client', 'ca-pub-******')
 ins.setAttribute('style', obj.style)
 ins.setAttribute('data-ad-slot', obj.slot)
 content.appendChild(ins)
 var inlineScript = document.createElement('script')
 inlineScript.type = 'text/javascript'
 inlineScript.text = '(adsbygoogle = window.adsbygoogle || []).push({});'
 document.getElementsByTagName('body')[0].appendChild(inlineScript)
})
}

调用方法


window.onload = function () {
var line = document.getElementById('ad_line'), // 横幅
 area = document.getElementById('ad_area')// 矩阵
if (!isYd()) { // 不为移动端

if (line) { //横幅
  addGoogel(line, {
   style: 'display:inline-block;width:1100px;height:160px',
   slot: '6183651273'
  })
}
 if (area) { //矩形
  addGoogel(area, {
   style: 'display:inline-block;width:250px;height:250px',
   slot: '1995310048'
  })
 }
}
}
0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com