温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-09-30 05:15:01 来源:脚本之家 阅读:186 作者:mdxy-dxy 栏目:开发技术

今天发现一个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'
   })
  }
 }
}

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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI