热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

这篇文章主要介绍了google广告之另类js调用实现代码,需要的朋友可以参考下

今天发现一个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广告内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!


推荐阅读
author-avatar
N个小灰流_701
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有