google广告之另类js调用实现代码
更新时间:2020年08月22日 23:37:06 投稿:mdxy-dxy
这篇文章主要介绍了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广告内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
您可能感兴趣的文章:
相关文章
javascript中JSON对象与JSON字符串相互转换实例
这篇文章主要介绍了javascript中JSON对象与JSON字符串相互转换,实例分析了json对象与字符串常用的几种转换技巧,具有一定参考借鉴价值,需要的朋友可以参考下2015-07-07
js动态添加onload、onresize、onscroll事件(另类方法)
window 的 onload、onresize、onscroll 事件,跟其他的事件不一样,它不能用 attachEvent 或 addEventListener 来添加于是本人想了一些另类的方法,需要了解的朋友可以参考下2012-12-12
js的map、flatMap和find、filter的使用详解
map和flatMap都是返回一个新数组,map不会改变数组长度,flatMap可以改变长度,find和filter都是过滤操作,find只会返回第一个找到的值,而filter会返回全部符合要求的对象2024-12-12
详解Python中logging日志模块在多进程环境下的使用
许多应用程序中都会有日志模块,用于记录系统在运行过程中的一些关键信息,以便于对系统的运行状况进行跟踪。这篇文章给大家主要介绍了在Python中logging日志模块在多进程环境下的使用,需要的朋友可以参考借鉴,下面来一起看看吧。2016-12-12


最新评论