今天發現一個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廣告內容請搜索億速云以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持億速云!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。