当前位置: 移动技术网 > IT编程>开发语言>JavaScript > google广告之另类js调用实现代码

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

2020年08月23日  | 移动技术网IT编程  | 我要评论
今天发现一个google广告的另类调用方法function addgoogel (content, obj) { addscript('///

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

function addgoogel (content, obj) {
 addscript('///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'
   })
  }
 }
}

到此这篇关于google广告之另类js调用实现代码的文章就介绍到这了,更多相关js google广告内容请搜索移动技术网以前的文章或继续浏览下面的相关文章希望大家以后多多支持移动技术网!

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网