首页 >> js开发 >> JavaScriptgoogle广告之另类js调用实现代码
JavaScriptgoogle广告之另类js调用实现代码
发布时间: 2021年1月13日 | 浏览:
| 分类: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)
})
}
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'
})
}
}
}
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'
})
}
}
}
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)
})
}
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'
})
}
}
}
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'
})
}
}
}
相关文章:
- js解决VUE项目使用Element-ui 下拉组件的验证失效问题js大全
- jsJavascript中Math.max和Math.max.apply的区别和用法详解js大全
- js微信小程序实现自定义动画弹框/提示框的方法实例js大全
- js微信小程序自定义tabBar的踩坑实践记录js大全
- JavaScript工作中常用js功能汇总
- jsnuxt 路由、过渡特效、中间件的实现代码js大全
- js微信小程序中target和currentTarget的区别小结js大全
- jsnuxt静态部署打包相对路径操作js大全
- js解决nuxt页面中mounted、created、watch执行两遍的问题js大全
- js解决VUE 在IE下出现ReferenceError: Promise未定义的问题js大全