我有一个可以自动放置的博客网站,但我认为这毁了我的文章。我想通过替换想要广告的文本来制作自定义 Adsense 展示位置。例如,我希望文本“showadshere”成为广告。我搜索过 Javascript DOM 但没有成功。
我希望可以用广告替换文章中的特定文字。
这是一种方法。 您的 HTML 页面 :
<div id="adslot">show ads here</div>
您的广告脚本:
var slot = document.querySelector('#adslot');
//check if slot exists on the page
if(slot) {
//prepare your adsense script / html tags
var adsense = '<scr'+'ipt async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-yourAdsenseID" crossorigin="anonymous"></scr'+'ipt><ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-yourSlotID" data-ad-slot="'+ slot.id +'" data-ad-format="auto" data-full-width-responsive="true"></ins><scr'+'ipt> (adsbygoogle = window.adsbygoogle || []).push({});</scr'+'ipt>';
//inject adsense node
slot.innerHTML = adsense ;
}